示例#1
0
 public function testPutWhenFull()
 {
     $lru = new LRUCache(3);
     $key1 = 'key1';
     $value1 = 'value1forkey1';
     $key2 = 'key2';
     $value2 = 'value2forkey2';
     $key3 = 'key3';
     $value3 = 'value3forkey3';
     $key4 = 'key4';
     $value4 = 'value4forkey4';
     // fill the cache
     $lru->put($key1, $value1);
     $lru->put($key2, $value2);
     $lru->put($key3, $value3);
     // access some elements more often
     $lru->get($key2);
     $lru->get($key2);
     $lru->get($key3);
     // put a new entry to force cache to discard the oldest
     $lru->put($key4, $value4);
     $this->assertNull($lru->get($key1));
 }