|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Cache; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\SimpleCache\CacheInterface; |
|
8
|
|
|
use Yiisoft\Cache\CacheKeyNormalizer; |
|
9
|
|
|
use Yiisoft\Cache\Dependency\Dependency; |
|
10
|
|
|
use Yiisoft\Cache\Dependency\TagDependency; |
|
11
|
|
|
|
|
12
|
|
|
final class SchemaCache |
|
13
|
|
|
{ |
|
14
|
|
|
private CacheInterface $cache; |
|
15
|
|
|
private bool $enabled = true; |
|
16
|
|
|
private int $duration = 3600; |
|
17
|
|
|
private array $exclude = []; |
|
18
|
2988 |
|
private CacheKeyNormalizer $keyNormalizer; |
|
19
|
|
|
|
|
20
|
2988 |
|
public function __construct(CacheInterface $cache, CacheKeyNormalizer $keyNormalizer) |
|
21
|
2988 |
|
{ |
|
22
|
2988 |
|
$this->cache = $cache; |
|
23
|
|
|
$this->keyNormalizer = $keyNormalizer; |
|
24
|
18 |
|
} |
|
25
|
|
|
|
|
26
|
18 |
|
public function delete($key): bool |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->cache->delete($key); |
|
29
|
1613 |
|
} |
|
30
|
|
|
|
|
31
|
1613 |
|
public function normalize($key): string |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->keyNormalizer->normalize($key); |
|
34
|
1535 |
|
} |
|
35
|
|
|
|
|
36
|
1535 |
|
public function get($key, $default = null) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->cache->get($key, $default); |
|
39
|
1595 |
|
} |
|
40
|
|
|
|
|
41
|
1595 |
|
public function getDuration(): int |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->duration; |
|
44
|
1613 |
|
} |
|
45
|
|
|
|
|
46
|
1613 |
|
public function isExclude(string $value): bool |
|
47
|
|
|
{ |
|
48
|
|
|
return in_array($value, $this->exclude, true); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function invalidate(string $cacheTag): void |
|
52
|
|
|
{ |
|
53
|
|
|
TagDependency::invalidate($this->cache, $cacheTag); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function isEnabled(): bool |
|
57
|
|
|
{ |
|
58
|
39 |
|
return $this->enabled; |
|
59
|
|
|
} |
|
60
|
39 |
|
|
|
61
|
39 |
|
public function set($key, $value, $ttl = null, Dependency $dependency = null): bool |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->cache->set($key, $value, $ttl, $dependency); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Whether to enable schema caching. Note that in order to enable truly schema caching, a valid cache component as |
|
68
|
|
|
* specified must be enabled and {@see setEnable()} must be set true. |
|
69
|
|
|
* |
|
70
|
|
|
* @param bool $value |
|
71
|
|
|
* |
|
72
|
|
|
* {@see setduration()} |
|
73
|
|
|
* {@see setExclude()} |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setEnable(bool $value): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->enabled = $value; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Number of seconds that table metadata can remain valid in cache. Use 0 to indicate that the cached data will |
|
82
|
|
|
* never expire. |
|
83
|
|
|
* |
|
84
|
|
|
* @param int $value |
|
85
|
|
|
* |
|
86
|
|
|
* {@see setEnable()} |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setDuration(int $value): void |
|
89
|
|
|
{ |
|
90
|
|
|
$this->duration = $value; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* List of tables whose metadata should NOT be cached. Defaults to empty array. The table names may contain schema |
|
95
|
|
|
* prefix, if any. Do not quote the table names. |
|
96
|
|
|
* |
|
97
|
|
|
* @param array $value |
|
98
|
|
|
* |
|
99
|
|
|
* {@see setEnable()} |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setExclude(array $value): void |
|
102
|
|
|
{ |
|
103
|
|
|
$this->exclude = $value; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.