Skip to content

Commit

Permalink
Merge pull request #8 from Vectorial1024/use_laravel
Browse files Browse the repository at this point in the history
Adopt Laravel's Number::fileSize()
  • Loading branch information
Vectorial1024 authored Jan 12, 2025
2 parents 46da805 + 8a26088 commit 3f47030
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 evicted storage size 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
Expand All @@ -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

4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
],
"require": {
"php": "^8.1",
"ext-intl": "*",
"illuminate/support": "^10.0|^11.0",
"wilderborn/partyline": "^1.0"
},
Expand All @@ -50,5 +51,8 @@
"Vectorial1024\\LaravelCacheEvict\\CacheEvictServiceProvider"
]
}
},
"config": {
"sort-packages": true
}
}
8 changes: 3 additions & 5 deletions src/AbstractEvictStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3f47030

Please sign in to comment.