Skip to content

Commit 3f47030

Browse files
Merge pull request #8 from Vectorial1024/use_laravel
Adopt Laravel's Number::fileSize()
2 parents 46da805 + 8a26088 commit 3f47030

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ Note: you may refer to `README.md` for description of features.
33

44
## Dev (WIP)
55

6-
## 1.0.3 (2025-01-17)
6+
## 2.0.0 (2025-01-12)
7+
- Adopted Laravel's `Number::fileSize()` to show the estimated evicted storage size stats
8+
- Therefore, further requires `ext-intl`
9+
10+
## 1.0.3 (2025-01-07)
711
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!!!
812
- No longer depends on `ramazancetinkaya/byte-formatter` as culprit of rugpull
913
- 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
2630
- Supports the `file` and `database` cache driver
2731
- Supports self-defined cache eviction strategies
2832
- Uses PHP generators to avoid using too much memory while scanning for expired items
29-

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
],
3434
"require": {
3535
"php": "^8.1",
36+
"ext-intl": "*",
3637
"illuminate/support": "^10.0|^11.0",
3738
"wilderborn/partyline": "^1.0"
3839
},
@@ -50,5 +51,8 @@
5051
"Vectorial1024\\LaravelCacheEvict\\CacheEvictServiceProvider"
5152
]
5253
}
54+
},
55+
"config": {
56+
"sort-packages": true
5357
}
5458
}

src/AbstractEvictStrategy.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Vectorial1024\LaravelCacheEvict;
44

55
use Illuminate\Console\OutputStyle;
6+
use Illuminate\Support\Number;
67
use Symfony\Component\Console\Input\StringInput;
78
use Symfony\Component\Console\Output\NullOutput;
89

@@ -41,10 +42,7 @@ abstract public function execute();
4142
*/
4243
protected function bytesToHuman(int $bytes): string
4344
{
44-
// the guy did a rugpull; the link turned out to be very handy.
45-
// see https://stackoverflow.com/questions/15188033/human-readable-file-size
46-
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
47-
for ($i = 0; $bytes > 1024; $i++) $bytes /= 1024;
48-
return round($bytes, 2) . ' ' . $units[$i];
45+
// it turns out Laravel already has a helper for this
46+
return Number::fileSize($bytes, 2, 2);
4947
}
5048
}

0 commit comments

Comments
 (0)