Skip to content
LRU Cache implementation in PHP
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/LRUCache Data is a mixed value Dec 5, 2014
test Added test to new remove() method Jul 24, 2013
.gitignore Added composer packaging. Mar 9, 2013
.travis.yml Add composer install to before_script in travis config Dec 7, 2014
LICENSE Added MIT license file. Mar 22, 2012
README.md Added travis-ci Jul 13, 2013
composer.json
phpunit.xml Undo last commit. Add bootstrap attribute in phpunit.xml Dec 7, 2014

README.md

Build Status

PHP LRU Cache implementation

Intro

WTF 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": {
    "lrucache/lrucache": "master-dev"
}

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.

You can’t perform that action at this time.