Download the PHP package nicklasw/lrucache without Composer
On this page you can find all versions of the php package nicklasw/lrucache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nicklasw/lrucache
More information about nicklasw/lrucache
Files in nicklasw/lrucache
Package lrucache
Short Description PHP LRU Cache implementation
License MIT
Homepage https://github.com/rogeriopvl/php-lrucache
Informations about the package lrucache
PHP LRU Cache implementation
Forked from https://github.com/rogeriopvl/php-lrucache
Changes
- Reduce cost of inserting to cache from O(n) to O(1)
- Make cache iterable
- Fix phpunit tests
Intro
What is a LRU Cache?
LRU stands for Least Recently Used. It's a type of cache that usually has a fixed capacity and discards the oldest entries. This is specially useful if you have the need to control the cache memory usage.
If you want more details about LRU Cache, you can read this article that explains it pretty well. Also if you want more interesting info, you can read this great paper on LRU algorithms.
Implementation
This code is in it's early stages. I need to write more tests to find out the possible naive code parts in order to achieve some performance, if any is possible with PHP :P
This implementation is similar to a LinkedHashMap. Right now I'm just messing around with the code and decided to keep it simple, using a simple associative array as a naive hashmap.
Install (composer)
Add the package into your composer.json
file:
"require": {
"justin-robinson/lrucache": "dev-master"
}
Then run the command:
composer install
Usage
Usage is pretty simple:
require_once('vendor/autoload.php'); // composer autoader
$cache = new \LRUCache\LRUCache(1000);
$cache->put('mykey', 'arrow to the knee');
echo $cache->get('mykey');
You can use the tests to try things like load testing etc.