Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
70.00% |
7 / 10 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ConfigCacheInvalidator | |
70.00% |
7 / 10 |
|
66.67% |
2 / 3 |
3.24 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
makeInvalidateTimestampKey | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
invalidate | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\MediaUploader\Config; |
4 | |
5 | use WANObjectCache; |
6 | |
7 | /** |
8 | * A relatively lightweight class intended for use when the config cache has to be |
9 | * explicitly invalidated. |
10 | */ |
11 | class ConfigCacheInvalidator { |
12 | |
13 | /** @var WANObjectCache */ |
14 | private $cache; |
15 | |
16 | /** |
17 | * @param WANObjectCache $cache |
18 | */ |
19 | public function __construct( WANObjectCache $cache ) { |
20 | $this->cache = $cache; |
21 | } |
22 | |
23 | /** |
24 | * Returns the key used to store the last time the config cache was invalidated. |
25 | * |
26 | * @param string ...$additionalComponents Additional cache key components |
27 | * |
28 | * @return string |
29 | */ |
30 | public function makeInvalidateTimestampKey( string ...$additionalComponents ): string { |
31 | return $this->cache->makeKey( |
32 | 'mediauploader', |
33 | 'parsed-config', |
34 | 'invalidate', |
35 | ...$additionalComponents |
36 | ); |
37 | } |
38 | |
39 | /** |
40 | * Invalidate the cache for the corresponding config, in all languages and genders. |
41 | * |
42 | * Does so by simply writing a new invalidate timestamp to cache. |
43 | * Since this invalidate timestamp is checked on every read, the cached entries |
44 | * for the config will be regenerated the next time there is a read. |
45 | * |
46 | * @param string ...$additionalComponents |
47 | */ |
48 | public function invalidate( string ...$additionalComponents ): void { |
49 | $this->cache->touchCheckKey( |
50 | $this->makeInvalidateTimestampKey( ...$additionalComponents ) |
51 | ); |
52 | } |
53 | } |