PHPackages                             onoi/cache - 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. onoi/cache

ActiveLibrary[Caching](/categories/caching)

onoi/cache
==========

A minimalistic cache adapter interface library

1.2.0(10y ago)2531.9k↑113%2[1 PRs](https://github.com/onoi/cache/pulls)13GPL-2.0+PHPPHP &gt;=5.3.2

Since Jan 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/onoi/cache)[ Packagist](https://packagist.org/packages/onoi/cache)[ Docs](https://github.com/onoi/cache)[ RSS](/packages/onoi-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (5)Used By (13)

Cache
=====

[](#cache)

[![Build Status](https://camo.githubusercontent.com/cbea88aa10c866d331edaf9bbd8084aae460fd4bd3c20841a9f4ee1d442cd3e0/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6f6e6f692f63616368652e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/onoi/cache)[![Code Coverage](https://camo.githubusercontent.com/bb470ce6ff5652298b1ad19af1fb707653a50a4a9e7166764833ab5bd33b56ac/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e6f692f63616368652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/onoi/cache/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/11d4888b6e25e7323afddae04b46a1b8800a3456d8d235688bb54030fa9096f2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e6f692f63616368652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/onoi/cache/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/2d76879d58f5c3e23ba1d09afb9035bf7bc0863376e995af74cf1c63a1d90cda/68747470733a2f2f706f7365722e707567782e6f72672f6f6e6f692f63616368652f76657273696f6e2e706e67)](https://packagist.org/packages/onoi/cache)[![Packagist download count](https://camo.githubusercontent.com/79ea64e630d0972c8a4d927461a4eed61265ea6379063fa2c249e604f2c72c99/68747470733a2f2f706f7365722e707567782e6f72672f6f6e6f692f63616368652f642f746f74616c2e706e67)](https://packagist.org/packages/onoi/cache)[![Dependency Status](https://camo.githubusercontent.com/8739b58372fa0f360354aa1bf85860126125bca69b48bd544eadbfa6dda259e3/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f6f6e6f693a63616368652f62616467652e706e67)](https://www.versioneye.com/php/onoi:cache)

A minimalistic cache adapter interface that was part of the [Semantic MediaWiki](https://github.com/SemanticMediaWiki/SemanticMediaWiki/) code base and is now being deployed as independent library.

- Support for MediaWiki's `BagOStuff` cache interface
- Support for the `Doctrine` cache interface
- Support for the `Zend` cache (ZF2) interface
- Provides a `FixedInMemoryLruCache` array [LRU](https://en.wikipedia.org/wiki/Least_Recently_Used) cache without any external cache provider dependency
- Provides a `CompositeCache` to combine different cache instances and allow access through hierarchical iteration on a first-come first-served basis

Requirements
------------

[](#requirements)

PHP 5.3 / HHVM 3.3 or later

Installation
------------

[](#installation)

The recommended installation method for this library is by either adding the dependency to your [composer.json](https://getcomposer.org/).

```
{
	"require": {
		"onoi/cache": "~1.1"
	}
}
```

Usage
-----

[](#usage)

```
use Onoi\Cache\Cache;

class Foo {

	private $cache = null;

	public function __constructor( Cache $cache ) {
		$this->cache = $cache;
	}

	public function doSomething( $id ) {

		if ( $this->cache->contains( $id ) ) {
			// do something
		}
	}
}
```

```
$cacheFactory = new CacheFactory();

$instance = new Foo( $cacheFactory->newFixedInMemoryLruCache( 500 ) );
$instance->doSomething( 'bar' );

or

$compositeCache = $cacheFactory->newCompositeCache( array(
	$cacheFactory->newFixedInMemoryLruCache( 500 ),
	$cacheFactory->newDoctrineCache( new \Doctrine\Common\Cache\RedisCache() ),
	$cacheFactory->newMediaWikiCache( new \SqlBagOStuf() )
) );

$instance = new Foo( $compositeCache );
$instance->doSomething( 'bar' );
```

Contribution and support
------------------------

[](#contribution-and-support)

If you want to contribute work to the project please subscribe to the developers mailing list and have a look at the [contribution guidelinee](/CONTRIBUTING.md). A list of people who have made contributions in the past can be found [here](https://github.com/onoi/cache/graphs/contributors).

- [File an issue](https://github.com/onoi/cache/issues)
- [Submit a pull request](https://github.com/onoi/cache/pulls)

### Tests

[](#tests)

The library provides unit tests that covers the core-functionality normally run by the [continues integration platform](https://travis-ci.org/onoi/cache). Tests can also be executed manually using the `composer phpunit` command from the root directory.

### Release notes

[](#release-notes)

- 1.2.0 (2015-06-02)
- Added `Cache::getName`
- Removed deprecated `FixedInMemoryCache`
- 1.1.0 (2015-03-29)
- Added `NullCache`
- Added `ZendCache`
- Renamed `FixedInMemoryCache` to `FixedInMemoryLruCache`
- 1.0.0 (2015-01-16)
- Initial release

License
-------

[](#license)

[GNU General Public License 2.0 or later](https://www.gnu.org/copyleft/gpl.html).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% 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 ~68 days

Total

3

Last Release

4003d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/372f9bc1233d5518b9522cb681210a8de2765a3a9bbde20138f6ad5332a411ca?d=identicon)[mwjames](/maintainers/mwjames)

![](https://www.gravatar.com/avatar/511b3dbc1a73ad7b69118e540b16c8bcc2ac5f923022b94aa61a8d71af612f9c?d=identicon)[onoi](/maintainers/onoi)

---

Top Contributors

[![mwjames](https://avatars.githubusercontent.com/u/1245473?v=4)](https://github.com/mwjames "mwjames (31 commits)")[![kghbln](https://avatars.githubusercontent.com/u/1104078?v=4)](https://github.com/kghbln "kghbln (1 commits)")

---

Tags

cache

### Embed Badge

![Health badge](/badges/onoi-cache/health.svg)

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

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[psr/cache

Common interface for caching libraries

5.2k686.9M1.3k](/packages/psr-cache)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[beste/in-memory-cache

A PSR-6 In-Memory cache that can be used as a fallback implementation and/or in tests.

2512.2M6](/packages/beste-in-memory-cache)[anahkiasen/flatten

A package for the Illuminate framework that flattens pages to plain HTML

33113.0k](/packages/anahkiasen-flatten)[rtcamp/nginx-helper

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

23517.0k1](/packages/rtcamp-nginx-helper)

PHPackages © 2026

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