PHPackages                             justin-robinson/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. justin-robinson/lrucache

ActiveLibrary[Caching](/categories/caching)

justin-robinson/lrucache
========================

PHP LRU Cache implementation

v1.1.0(10y ago)13.0k11Apache-2.0PHPPHP &gt;=5.4.0

Since Mar 9Pushed 10y ago1 watchersCompare

[ Source](https://github.com/justin-robinson/php-lrucache)[ Packagist](https://packagist.org/packages/justin-robinson/lrucache)[ Docs](https://github.com/justin-robinson/php-lrucache)[ RSS](/packages/justin-robinson-lrucache/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (4)Versions (14)Used By (1)

[![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

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 97.1% 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 ~107 days

Recently: every ~5 days

Total

12

Last Release

3679d ago

Major Versions

v0.6.0 → v1.0.02016-05-17

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

v0.4.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3090489?v=4)[Justin Robinson](/maintainers/justin-robinson)[@justin-robinson](https://github.com/justin-robinson)

---

Top Contributors

[![rogeriopvl](https://avatars.githubusercontent.com/u/38240?v=4)](https://github.com/rogeriopvl "rogeriopvl (34 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/justin-robinson-lrucache/health.svg)

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

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

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

PHP LRU Cache implementation

67121.8k3](/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/

202570.3k8](/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)
