Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rogeriopvl/php-lrucache
LRU Cache implementation in PHP
https://github.com/rogeriopvl/php-lrucache
Last synced: 8 days ago
JSON representation
LRU Cache implementation in PHP
- Host: GitHub
- URL: https://github.com/rogeriopvl/php-lrucache
- Owner: rogeriopvl
- License: mit
- Created: 2012-03-22T12:16:55.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-12-07T21:32:22.000Z (almost 10 years ago)
- Last Synced: 2024-10-08T11:10:14.850Z (about 1 month ago)
- Language: PHP
- Homepage: http://github.com/rogeriopvl/phpLRUCache
- Size: 169 KB
- Stars: 65
- Watchers: 9
- Forks: 29
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- php-awesome - php-lrucache - LRU 算法缓存实现 (类库 / 缓存)
README
[![Build Status](https://travis-ci.org/rogeriopvl/php-lrucache.png)](https://travis-ci.org/rogeriopvl/php-lrucache)
# 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][0] that explains it pretty well. Also if you want more interesting info, you can read [this great paper on LRU algorithms][1].
### 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][2]. 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.
[0]: http://java-planet.blogspot.pt/2005/08/how-to-set-up-simple-lru-cache-using.html
[1]: http://www.vldb.org/conf/1994/P439.PDF
[2]: http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html