Skip to content

Commit 4217f0c

Browse files
committed
Add CacheKeyGenerator::Version
1 parent 318baa9 commit 4217f0c

File tree

4 files changed

+7
-45
lines changed

4 files changed

+7
-45
lines changed

src/CacheKeyGenerator.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
class CacheKeyGenerator {
1212

1313
/**
14-
* External (hence auxiliary) cache key modifier that can be used to alter
15-
* existing keys
14+
* Update the version to force a recache for all items due to
15+
* required changes
1616
*/
17-
private $auxiliaryKeyModifier = '';
17+
const VERSION = '1.1';
1818

1919
/**
2020
* @var string|null
@@ -33,18 +33,6 @@ public function setCachePrefix( $cachePrefix ) {
3333
return $this;
3434
}
3535

36-
/**
37-
* @since 1.0
38-
*
39-
* @param string $auxiliaryKeyModifier
40-
*
41-
* @return CacheKeyGenerator
42-
*/
43-
public function setAuxiliaryKeyModifier( $auxiliaryKeyModifier ) {
44-
$this->auxiliaryKeyModifier = $auxiliaryKeyModifier;
45-
return $this;
46-
}
47-
4836
/**
4937
* @since 1.0
5038
*
@@ -53,7 +41,7 @@ public function setAuxiliaryKeyModifier( $auxiliaryKeyModifier ) {
5341
* @return string
5442
*/
5543
public function getSiteCacheKey( $key ) {
56-
return $this->getCachePrefix() . 's:' . md5( $key . $this->auxiliaryKeyModifier );
44+
return $this->getCachePrefix() . 's:' . md5( $key . self::VERSION );
5745
}
5846

5947
/**
@@ -64,7 +52,7 @@ public function getSiteCacheKey( $key ) {
6452
* @return string
6553
*/
6654
public function getPageLanguageCacheBlobKey( $key = '' ) {
67-
return $this->getCachePrefix() . 'b:' . md5( $key . $this->auxiliaryKeyModifier );
55+
return $this->getCachePrefix() . 'b:' . md5( $key . self::VERSION );
6856
}
6957

7058
/**
@@ -76,7 +64,7 @@ public function getPageLanguageCacheBlobKey( $key = '' ) {
7664
* @return string
7765
*/
7866
public function getPageCacheKey( $key, $stable = true ) {
79-
return $this->getCachePrefix() . 'p:' . md5( $key . ( $stable ? '' : $this->auxiliaryKeyModifier ) );
67+
return $this->getCachePrefix() . 'p:' . md5( $key . ( $stable ? '' : self::VERSION ) );
8068
}
8169

8270
/**

src/HookRegistry.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public function register() {
6969
private function addCallbackHandlers( $store, $cache, $cachePrefix ) {
7070

7171
$cacheKeyGenerator = new CacheKeyGenerator();
72-
$cacheKeyGenerator->setAuxiliaryKeyModifier( '20150122' );
7372
$cacheKeyGenerator->setCachePrefix( $cachePrefix );
7473

7574
$languageTargetLinksCache = new LanguageTargetLinksCache(

tests/phpunit/Unit/CacheKeyGeneratorTest.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,10 @@ public function testGetSiteCacheKey() {
2828

2929
$instance = new CacheKeyGenerator();
3030

31-
$this->assertNotSame(
32-
$instance
33-
->setAuxiliaryKeyModifier( 'foo' )
34-
->getSiteCacheKey( 'foo' ),
35-
$instance
36-
->setAuxiliaryKeyModifier( 'bar' )
37-
->getSiteCacheKey( 'foo' )
38-
);
39-
4031
$this->assertSame(
4132
$instance
42-
->setAuxiliaryKeyModifier( 'bar' )
4333
->getSiteCacheKey( 'foo' ),
4434
$instance
45-
->setAuxiliaryKeyModifier( 'bar' )
4635
->getSiteCacheKey( 'foo' )
4736
);
4837
}
@@ -51,12 +40,10 @@ public function testGetPageLanguageCacheBlobKey() {
5140

5241
$instance = new CacheKeyGenerator();
5342

54-
$this->assertNotSame(
43+
$this->assertSame(
5544
$instance
56-
->setAuxiliaryKeyModifier( 'foo' )
5745
->getPageLanguageCacheBlobKey( 'foo' ),
5846
$instance
59-
->setAuxiliaryKeyModifier( 'bar' )
6047
->getPageLanguageCacheBlobKey( 'foo' )
6148
);
6249
}
@@ -65,21 +52,10 @@ public function testGetPageCacheKey() {
6552

6653
$instance = new CacheKeyGenerator();
6754

68-
$this->assertNotSame(
69-
$instance
70-
->setAuxiliaryKeyModifier( 'foo' )
71-
->getPageCacheKey( 'foo', false ),
72-
$instance
73-
->setAuxiliaryKeyModifier( 'bar' )
74-
->getPageCacheKey( 'foo', false )
75-
);
76-
7755
$this->assertSame(
7856
$instance
79-
->setAuxiliaryKeyModifier( 'foo' )
8057
->getPageCacheKey( 'foo', true ),
8158
$instance
82-
->setAuxiliaryKeyModifier( 'bar' )
8359
->getPageCacheKey( 'foo', true )
8460
);
8561
}

tests/phpunit/Unit/LanguageTargetLinksCacheTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ public function testUpdatePageLanguageToCache( $pageLanguageCacheStrategy ) {
318318
$this->equalTo( $data ) );
319319

320320
$cacheKeyGenerator = new CacheKeyGenerator();
321-
$cacheKeyGenerator->setAuxiliaryKeyModifier( '20150122' );
322321
$cacheKeyGenerator->setCachePrefix( 'foo' );
323322

324323
$instance = new LanguageTargetLinksCache( $cache, $cacheKeyGenerator );

0 commit comments

Comments
 (0)