diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3605727 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,29 @@ +# Change Log of `laravel-cache-evict` +Note: you may refer to `README.md` for description of features. + +## Dev (WIP) + +## 1.0.3 (2025-01-17) +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 + - A proper solution will be made later +- Added a changelog at `ChANGELOG.md` + +## 1.0.2 (2024-10-29) +Hotfix: avoid `database` eviction race condition (38d70027b1778685a3c5ddffb4e10a9892bf4896); improve test case stability (2f7fecf581d5598231671ba5511e219aa94122b3) + +## 1.0.1 (2024-10-29) +The v1.0.1 release of the library. +- Added the earlier-promised auto tests (#2) +- Reorganized the README +- Removed `package.json` (#2) to fix possible installation failures + +## 1.0.0 (2024-10-27) +Initial release. + +This is a utility library for Laravel that can efficiently remove many expired cache items in Laravel to prevent storage overload. +- 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 + diff --git a/README.md b/README.md index fd0e558..c25ac6a 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,9 @@ Some drivers (e.g. `memcached`, `redis`) will never be supported because they ha Custom eviction strategies can be defined for other cache drivers that does not have their own eviction mechanisms (see FAQ section). +### Change log +Please see `CHANGELOG.md`. + ## Usage You may run this in the command line: @@ -94,7 +97,7 @@ php artisan cache:evict local_store ... then, you will only evict the `local_store` cache. The `another_store` cache is unaffected by this command (assuming both are using separate directories, of course). ## Testing -Using `orchestra/testbench` (customized PHPUnit) via Composer: +PHPUnit (using `orchestra/testbench`) via Composer: ```sh composer run-script test diff --git a/composer.json b/composer.json index eb2e378..9b75740 100644 --- a/composer.json +++ b/composer.json @@ -34,8 +34,7 @@ "require": { "php": "^8.1", "illuminate/support": "^10.0|^11.0", - "wilderborn/partyline": "^1.0", - "ramazancetinkaya/byte-formatter": "^1.0" + "wilderborn/partyline": "^1.0" }, "require-dev": { "ext-sqlite3": "*", diff --git a/src/AbstractEvictStrategy.php b/src/AbstractEvictStrategy.php index b2ed9d4..26143bc 100644 --- a/src/AbstractEvictStrategy.php +++ b/src/AbstractEvictStrategy.php @@ -3,7 +3,6 @@ namespace Vectorial1024\LaravelCacheEvict; use Illuminate\Console\OutputStyle; -use ramazancetinkaya\ByteFormatter; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\NullOutput; @@ -42,8 +41,10 @@ abstract public function execute(); */ protected function bytesToHuman(int $bytes): string { - // in case the library broke, we can refer to this link: https://stackoverflow.com/questions/15188033/human-readable-file-size - $formatter = new ByteFormatter(); - return $formatter->format($bytes); + // 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]; } }