1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace RemotelyLiving\PHPCacheAdapter\SimpleCache; |
||
6 | |||
7 | use Psr\SimpleCache; |
||
8 | use RemotelyLiving\PHPCacheAdapter\Assertions; |
||
9 | |||
10 | final class APCu extends AbstractAdapter |
||
11 | { |
||
12 | private function __construct() |
||
13 | { |
||
14 | Assertions::assertExtensionLoaded('apcu'); |
||
15 | ini_set('apc.use_request_time', '0'); |
||
16 | } |
||
17 | |||
18 | public static function create(): SimpleCache\CacheInterface |
||
19 | { |
||
20 | return new self(); |
||
21 | } |
||
22 | |||
23 | public function flush(): bool |
||
24 | { |
||
25 | return \apcu_clear_cache(); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @inheritDoc |
||
30 | * @psalm-suppress InvalidArgument MoreSpecificImplementedParamType |
||
31 | */ |
||
32 | protected function multiGet(array $keys, $default = null): \Generator |
||
33 | { |
||
34 | $results = \apcu_fetch($keys); |
||
35 | foreach ($keys as $key) { |
||
36 | yield $key => $results[$key] ?? $default; |
||
37 | } |
||
38 | } |
||
39 | |||
40 | protected function multiSave(array $values, int $ttl = null): bool |
||
41 | { |
||
42 | \apcu_store($values, null, (int) $ttl); |
||
43 | |||
44 | return true; |
||
45 | } |
||
46 | |||
47 | protected function multiDelete(array $keys): bool |
||
48 | { |
||
49 | return \apcu_delete(new \APCUIterator($keys)); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
50 | } |
||
51 | |||
52 | protected function exists(string $key): bool |
||
53 | { |
||
54 | return \apcu_exists($key); |
||
0 ignored issues
–
show
|
|||
55 | } |
||
56 | } |
||
57 |