1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Cache; |
4
|
|
|
|
5
|
|
|
use Yiisoft\Cache\Dependency\Dependency; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* NullCache does not cache anything reporting success for all methods calls. |
9
|
|
|
* |
10
|
|
|
* By replacing it with some other cache component, one can quickly switch from |
11
|
|
|
* non-caching mode to caching mode. |
12
|
|
|
*/ |
13
|
|
|
final class NullCache implements CacheInterface |
14
|
|
|
{ |
15
|
|
|
public function add($key, $value, $ttl = 0, Dependency $dependency = null): bool |
16
|
|
|
{ |
17
|
|
|
return true; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function deleteMultiple($keys): bool |
21
|
|
|
{ |
22
|
|
|
return true; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function set($key, $value, $ttl = null, Dependency $dependency = null): bool |
26
|
|
|
{ |
27
|
|
|
return true; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function get($key, $default = null) |
31
|
|
|
{ |
32
|
|
|
return $default; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getMultiple($keys, $default = null): iterable |
36
|
|
|
{ |
37
|
|
|
return array_fill_keys($this->iterableToArray($keys), $default); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function setMultiple($values, $ttl = null, Dependency $dependency = null): bool |
41
|
|
|
{ |
42
|
|
|
return true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function addMultiple(array $values, $ttl = null, Dependency $dependency = null): bool |
46
|
|
|
{ |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getOrSet($key, callable $callable, $ttl = null, Dependency $dependency = null) |
51
|
|
|
{ |
52
|
|
|
return $callable($this); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function delete($key): bool |
56
|
|
|
{ |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function clear(): bool |
61
|
|
|
{ |
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function has($key): bool |
66
|
|
|
{ |
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function enableKeyNormalization(): void |
71
|
|
|
{ |
72
|
|
|
// do nothing |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function disableKeyNormalization(): void |
76
|
|
|
{ |
77
|
|
|
// do nothing |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function setKeyPrefix(string $keyPrefix): void |
81
|
|
|
{ |
82
|
|
|
// do nothing |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function iterableToArray(iterable $iterable): array |
86
|
|
|
{ |
87
|
|
|
return $iterable instanceof \Traversable ? iterator_to_array($iterable) : (array)$iterable; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|