Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 430 Bytes

README.md

File metadata and controls

21 lines (17 loc) · 430 Bytes

LRU Cache for PHP

https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU

Usage

use EJLin\LruCache\Cache;

$LRUCache = new Cache(2);

$LRUCache->put(1,1);
$LRUCache->put(2,2);
$LRUCache->get(1); // 1
$LRUCache->put(3,3);
$LRUCache->get(2); // -1 (not found)
$LRUCache->put(4,4);
$LRUCache->get(1); // -1 (not found)
$LRUCache->get(3); // 3
$LRUCache->get(4); // 4

$LRUCache->toArray(); // [4 => 4, 3 => 3];