+
+ /**
+ * Ensure maxKeys eviction prefers recently retrieved keys (LRU).
+ */
+ public function testEvictionGet() {
+ $cache = new HashBagOStuff( array( 'maxKeys' => 3 ) );
+
+ foreach ( array( 'foo', 'bar', 'baz' ) as $key ) {
+ $cache->set( $key, 1 );
+ }
+
+ // Get existing key
+ $cache->get( 'foo', 1 );
+
+ // Add a 4th key (beyond the allowed maximum)
+ $cache->set( 'quux', 1 );
+
+ // Foo's life should have been extended over Bar
+ foreach ( array( 'foo', 'baz', 'quux' ) as $key ) {
+ $this->assertEquals( 1, $cache->get( $key ), "Kept $key" );
+ }
+ $this->assertEquals( false, $cache->get( 'bar' ), 'Evicted bar' );
+ }