PHPackages                             millken/lrucache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. millken/lrucache

ActiveLibrary[Caching](/categories/caching)

millken/lrucache
================

PHP LRU Cache implementation

v1.0.1(7y ago)021Apache-2.0PHPPHP &gt;=5.4.0

Since Mar 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/millken/php-lrucache)[ Packagist](https://packagist.org/packages/millken/lrucache)[ Docs](https://github.com/millken/php-lrucache)[ RSS](/packages/millken-lrucache/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (0)

[![Build Status](https://camo.githubusercontent.com/c70243ecd03e2bcf7f45a4ffc5d3a06762b92e759e6a51797890abb1b28215ed/68747470733a2f2f7472617669732d63692e6f72672f6a757374696e2d726f62696e736f6e2f7068702d6c727563616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/justin-robinson/php-lrucache)[![Coverage Status](https://camo.githubusercontent.com/41df71cd7715f80b0553e601ef114232316bb3337a1eed39e301cea90b49d915/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a757374696e2d726f62696e736f6e2f7068702d6c727563616368652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/justin-robinson/php-lrucache?branch=master)

PHP LRU Cache implementation
============================

[](#php-lru-cache-implementation)

Forked from

Changes

- Reduce cost of inserting to cache from O(n) to O(1)
- Make cache iterable
- Fix phpunit tests

Intro
-----

[](#intro)

### What is a LRU Cache?

[](#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](http://java-planet.blogspot.pt/2005/08/how-to-set-up-simple-lru-cache-using.html) that explains it pretty well. Also if you want more interesting info, you can read [this great paper on LRU algorithms](http://www.vldb.org/conf/1994/P439.PDF).

### Implementation

[](#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](http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html). 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)
------------------

[](#install-composer)

Add the package into your `composer.json` file:

```
"require": {
    "justin-robinson/lrucache": "dev-master"
}

```

Then run the command:

```
composer install

```

Usage
-----

[](#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.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 94.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~666 days

Total

4

Last Release

2815d ago

Major Versions

v0.3.0 → v1.0.12018-08-30

PHP version history (2 changes)v0.1.3PHP &gt;=5.3.0

v1.0.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/45d31d24e1da038177a161d68296de2e36426a4d5b018efd491500d91c147921?d=identicon)[millken](/maintainers/millken)

---

Top Contributors

[![rogeriopvl](https://avatars.githubusercontent.com/u/38240?v=4)](https://github.com/rogeriopvl "rogeriopvl (34 commits)")[![millken](https://avatars.githubusercontent.com/u/176581?v=4)](https://github.com/millken "millken (1 commits)")[![nicolas-zozol](https://avatars.githubusercontent.com/u/912634?v=4)](https://github.com/nicolas-zozol "nicolas-zozol (1 commits)")

---

Tags

phpcachelru

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/millken-lrucache/health.svg)

```
[![Health](https://phpackages.com/badges/millken-lrucache/health.svg)](https://phpackages.com/packages/millken-lrucache)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[lrucache/lrucache

PHP LRU Cache implementation

67117.1k3](/packages/lrucache-lrucache)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[eftec/cacheone

A Cache library with minimum dependency

103.5k4](/packages/eftec-cacheone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
