Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| LaravelCache | |
87.50% |
7 / 8 |
|
75.00% |
3 / 4 |
4.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| delete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createItem | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\LaravelApie\Wrappers\Cache; |
| 4 | |
| 5 | use Illuminate\Contracts\Cache\Repository as Cache; |
| 6 | use Symfony\Contracts\Cache\CacheInterface; |
| 7 | use Symfony\Contracts\Cache\ItemInterface; |
| 8 | |
| 9 | class LaravelCache implements CacheInterface |
| 10 | { |
| 11 | public function __construct( |
| 12 | private readonly Cache $cache, |
| 13 | ) { |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * @param array<array-key, mixed>|null $metadata |
| 18 | */ |
| 19 | public function get( |
| 20 | string $key, |
| 21 | callable $callback, |
| 22 | ?float $beta = null, |
| 23 | ?array &$metadata = null, |
| 24 | ): mixed { |
| 25 | return $this->cache->remember( |
| 26 | $key, |
| 27 | now()->addMinutes(60), |
| 28 | fn () => $callback($this->createItem($key), true), |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | public function delete(string $key): bool |
| 33 | { |
| 34 | return $this->cache->forget($key); |
| 35 | } |
| 36 | |
| 37 | private function createItem(string $key): ItemInterface |
| 38 | { |
| 39 | return new LaravelCacheItem($key); |
| 40 | } |
| 41 | } |