PHP code example of m1n64 / lru-cache

1. Go to this page and download the library: Download m1n64/lru-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

m1n64 / lru-cache example snippets




asqo\LRU\LRUCache;

$cache = new LRUCache(3); // Create a cache with a capacity of 3 items

$cache->put('a', 1);
$cache->put('b', 2);
$cache->put('c', 3);

// Get an item
echo $cache->get('a'); // 1

$cache->put('d', 4); // 'b' will be removed as it is the least used

// Get all items
print_r($cache->all()); // ['a' => 1, 'c' => 3, 'd' => 4]

// Remove an item
$cache->remove('a');
print_r($cache->all()); // ['c' => 3, 'd' => 4]