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