From e8e5bed701f0bbf902d0a96a791fd7e992e974db Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sun, 12 Jan 2025 14:47:54 +0800 Subject: [PATCH 1/6] Use Laravel Number helper --- src/AbstractEvictStrategy.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/AbstractEvictStrategy.php b/src/AbstractEvictStrategy.php index 26143bc..b89ec86 100644 --- a/src/AbstractEvictStrategy.php +++ b/src/AbstractEvictStrategy.php @@ -3,6 +3,7 @@ namespace Vectorial1024\LaravelCacheEvict; use Illuminate\Console\OutputStyle; +use Illuminate\Support\Number; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\NullOutput; @@ -41,10 +42,7 @@ abstract public function execute(); */ protected function bytesToHuman(int $bytes): string { - // the guy did a rugpull; the link turned out to be very handy. - // see https://stackoverflow.com/questions/15188033/human-readable-file-size - $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; - for ($i = 0; $bytes > 1024; $i++) $bytes /= 1024; - return round($bytes, 2) . ' ' . $units[$i]; + // it turns out Laravel already has a helper for this + return Number::fileSize($bytes, 2, 2); } } From 267af06517b389e2d80d36332cdb72be2458cfcf Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sun, 12 Jan 2025 14:54:40 +0800 Subject: [PATCH 2/6] Specify extension as required --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 9b75740..08024e0 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ ], "require": { "php": "^8.1", + "ext-intl": "*", "illuminate/support": "^10.0|^11.0", "wilderborn/partyline": "^1.0" }, From 52fee63a8ce98830e18cf7de0c3aa313d74b0673 Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sun, 12 Jan 2025 14:56:47 +0800 Subject: [PATCH 3/6] Setup package sorting --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 08024e0..67a1aa1 100644 --- a/composer.json +++ b/composer.json @@ -51,5 +51,8 @@ "Vectorial1024\\LaravelCacheEvict\\CacheEvictServiceProvider" ] } + }, + "config": { + "sort-packages": true } } From be6573279fb581e35086d395d883d606643121ee Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sun, 12 Jan 2025 15:07:12 +0800 Subject: [PATCH 4/6] Add changelog --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f06fc8..de0be87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,11 @@ Note: you may refer to `README.md` for description of features. ## Dev (WIP) -## 1.0.3 (2025-01-17) +## 2.0.0 (2025-01-12) +- Adopted Laravel's `Number::fileSize()` to show the estimated file size cleaned stats + - Therefore, further requires `ext-intl` + +## 1.0.3 (2025-01-07) Special note: this update is made in response to the external rugpull as discovered in #4. All previous versions are "tainted" and will not be supported, effective immediately. Update your installed version now!!! - No longer depends on `ramazancetinkaya/byte-formatter` as culprit of rugpull - A StackOverflow-copied solution is being used for now @@ -26,4 +30,3 @@ This is a utility library for Laravel that can efficiently remove many expired c - Supports the `file` and `database` cache driver - Supports self-defined cache eviction strategies - Uses PHP generators to avoid using too much memory while scanning for expired items - From 36091de1d5735a1cf5e6292779d50cdcc1962d3d Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sun, 12 Jan 2025 15:08:15 +0800 Subject: [PATCH 5/6] Amend changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de0be87..f399c2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Note: you may refer to `README.md` for description of features. ## Dev (WIP) ## 2.0.0 (2025-01-12) -- Adopted Laravel's `Number::fileSize()` to show the estimated file size cleaned stats +- Adopted Laravel's `Number::fileSize()` to show the estimated storage size cleaned stats - Therefore, further requires `ext-intl` ## 1.0.3 (2025-01-07) From 8a26088010c67b15988625ddcb29af3deb03b12c Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sun, 12 Jan 2025 15:09:05 +0800 Subject: [PATCH 6/6] Amend changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f399c2d..5233f1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Note: you may refer to `README.md` for description of features. ## Dev (WIP) ## 2.0.0 (2025-01-12) -- Adopted Laravel's `Number::fileSize()` to show the estimated storage size cleaned stats +- Adopted Laravel's `Number::fileSize()` to show the estimated evicted storage size stats - Therefore, further requires `ext-intl` ## 1.0.3 (2025-01-07)