3use Wikimedia\TestingAccessWrapper;
10 use MediaWikiCoversValidator;
20 $backend->set(
'foo',
'bar' );
21 $this->assertEquals(
'bar',
$cache->get(
'foo' ) );
23 $backend->set(
'foo',
'baz' );
24 $this->assertEquals(
'bar',
$cache->get(
'foo' ),
'cached' );
35 for ( $i = 0; $i < 10; $i++ ) {
37 $this->assertEquals( 1,
$cache->get(
"key$i" ) );
38 $this->assertEquals( 1, $backend->get(
"key$i" ) );
40 $this->assertEquals(
false,
$cache->get(
"key$i" ) );
41 $this->assertEquals(
false, $backend->get(
"key$i" ) );
53 $cache->set(
'foo',
'bar', 0, CachedBagOStuff::WRITE_CACHE_ONLY );
54 $this->assertEquals(
'bar',
$cache->get(
'foo' ) );
55 $this->assertFalse( $backend->get(
'foo' ) );
57 $cache->set(
'foo',
'old' );
58 $this->assertEquals(
'old',
$cache->get(
'foo' ) );
59 $this->assertEquals(
'old', $backend->get(
'foo' ) );
61 $cache->set(
'foo',
'new', 0, CachedBagOStuff::WRITE_CACHE_ONLY );
62 $this->assertEquals(
'new',
$cache->get(
'foo' ) );
63 $this->assertEquals(
'old', $backend->get(
'foo' ) );
65 $cache->delete(
'foo', CachedBagOStuff::WRITE_CACHE_ONLY );
66 $this->assertEquals(
'old',
$cache->get(
'foo' ) );
77 $this->assertEquals(
false,
$cache->get(
'foo' ) );
80 $backend->set(
'foo',
true );
83 $this->assertEquals(
false,
$cache->get(
'foo' ) );
86 $backend->set(
'bar',
true );
87 $this->assertEquals(
true,
$cache->get(
'bar' ) );
97 $backend = TestingAccessWrapper::newFromObject( $backend );
99 $this->assertFalse( $backend->debugMode );
100 $this->assertFalse(
$cache->debugMode );
104 $this->assertTrue( $backend->debugMode,
'sets backend' );
105 $this->assertTrue(
$cache->debugMode,
'sets self' );
112 $backend = $this->getMockBuilder( HashBagOStuff::class )
113 ->setMethods( [
'deleteObjectsExpiringBefore' ] )
115 $backend->expects( $this->once() )
116 ->method(
'deleteObjectsExpiringBefore' )
117 ->willReturn(
false );
120 $cache->deleteObjectsExpiringBefore(
'20110401000000' );
127 $backend = $this->getMockBuilder( HashBagOStuff::class )
128 ->setMethods( [
'makeKey' ] )
130 $backend->method(
'makeKey' )
131 ->willReturn(
'special/logic' );
139 $this->assertEquals(
'special/logic', $backend->makeKey(
'special',
'logic' ) );
140 $this->assertEquals(
'special/logic',
$cache->makeKey(
'special',
'logic' ) );
147 $backend = $this->getMockBuilder( HashBagOStuff::class )
148 ->setMethods( [
'makeGlobalKey' ] )
150 $backend->method(
'makeGlobalKey' )
151 ->willReturn(
'special/logic' );
155 $this->assertEquals(
'special/logic', $backend->makeGlobalKey(
'special',
'logic' ) );
156 $this->assertEquals(
'special/logic',
$cache->makeGlobalKey(
'special',
'logic' ) );
testMakeKey()
CachedBagOStuff::makeKey.
testExpire()
CachedBagOStuff::deleteObjectsExpiringBefore.
testSetDebug()
CachedBagOStuff::setDebug.
testCacheBackendMisses()
CachedBagOStuff::doGet.
testMakeGlobalKey()
CachedBagOStuff::makeGlobalKey.
testSetAndDelete()
CachedBagOStuff::set CachedBagOStuff::delete.
testWriteCacheOnly()
CachedBagOStuff::set CachedBagOStuff::delete.
testGetFromBackend()
CachedBagOStuff::__construct CachedBagOStuff::doGet.
Wrapper around a BagOStuff that caches data in memory.
Simple store for keeping values in an associative array for the current process.