|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yiisoft\Cache; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* WinCache provides Windows Cache caching in terms of an application component. |
|
6
|
|
|
* |
|
7
|
|
|
* To use this application component, the [WinCache PHP extension](https://sourceforge.net/projects/wincache/) |
|
8
|
|
|
* must be loaded. Also note that "wincache.ucenabled" should be set to "1" in your php.ini file. |
|
9
|
|
|
* |
|
10
|
|
|
* See {@see \Psr\SimpleCache\CacheInterface} for common cache operations that are supported by WinCache. |
|
11
|
|
|
*/ |
|
12
|
|
|
final class WinCache extends SimpleCache |
|
13
|
|
|
{ |
|
14
|
|
|
private const TTL_INFINITY = 0; |
|
15
|
|
|
|
|
16
|
|
|
protected function hasValue(string $key): bool |
|
17
|
|
|
{ |
|
18
|
|
|
return \wincache_ucache_exists($key); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
protected function getValue(string $key, $default = null) |
|
22
|
|
|
{ |
|
23
|
|
|
$value = \wincache_ucache_get($key, $success); |
|
24
|
|
|
return $success ? $value : $default; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected function getValues(iterable $keys, $default = null): iterable |
|
28
|
|
|
{ |
|
29
|
|
|
$defaultValues = array_fill_keys($keys, $default); |
|
|
|
|
|
|
30
|
|
|
return array_merge($defaultValues, \wincache_ucache_get($keys)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function setValue(string $key, $value, ?int $ttl): bool |
|
34
|
|
|
{ |
|
35
|
|
|
return \wincache_ucache_set($key, $value, $ttl ?? self::TTL_INFINITY); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function setValues(iterable $values, ?int $ttl): bool |
|
39
|
|
|
{ |
|
40
|
|
|
return \wincache_ucache_set($values, null, $ttl ?? self::TTL_INFINITY) === []; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function deleteValue(string $key): bool |
|
44
|
|
|
{ |
|
45
|
|
|
return \wincache_ucache_delete($key); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function clear(): bool |
|
49
|
|
|
{ |
|
50
|
|
|
return \wincache_ucache_clear(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function deleteValues(iterable $keys): bool |
|
54
|
|
|
{ |
|
55
|
|
|
$deleted = array_flip(\wincache_ucache_delete($keys)); |
|
|
|
|
|
|
56
|
|
|
foreach ($keys as $expectedKey) { |
|
57
|
|
|
if (!isset($deleted[$expectedKey])) { |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
return true; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|