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

ActiveLibrary

corneltek/universal-cache
=========================

A Generic PHP Cache Interface with Cascade Caching

3.3.0(9y ago)207.0k1[3 issues](https://github.com/corneltek/UniversalCache/issues)1MITPHPPHP &gt;=5.4.0

Since Mar 26Pushed 9y ago2 watchersCompare

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

READMEChangelogDependencies (3)Versions (7)Used By (1)

UniversalCache
==============

[](#universalcache)

[![Build Status](https://camo.githubusercontent.com/512404457a0378bed1c07b186b663d68b4be72c00c4beaf2aab3db459b9643df/68747470733a2f2f7472617669732d63692e6f72672f636f726e656c74656b2f556e6976657273616c43616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/corneltek/UniversalCache)[![Latest Stable Version](https://camo.githubusercontent.com/edb727f841205367ff47f21660d498580fa69719cd3289f101d225e0970dbe70/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f756e6976657273616c2d63616368652f762f737461626c65)](https://packagist.org/packages/corneltek/universal-cache)[![Latest Unstable Version](https://camo.githubusercontent.com/98fa012d672d80f882b0be15e4c75b681de1aca8aac277ad549e4718142ac8e6/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f756e6976657273616c2d63616368652f762f756e737461626c65)](https://packagist.org/packages/corneltek/universal-cache)[![Total Downloads](https://camo.githubusercontent.com/5dc82952ae23ccdb79ad3f03b521d69ed61bc9dfafc9461e8f674d64b6ded579/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f756e6976657273616c2d63616368652f646f776e6c6f616473)](https://packagist.org/packages/corneltek/universal-cache)[![Monthly Downloads](https://camo.githubusercontent.com/cde183abefe9cc01128fe8ea5c428393bb68fd094762c329f625c05d6ae224db/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f756e6976657273616c2d63616368652f642f6d6f6e74686c79)](https://packagist.org/packages/corneltek/universal-cache)[![License](https://camo.githubusercontent.com/4c4147e894360e79afa4486e80f015f5a1ff29cc1cb40c8944bcf249998564b2/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f756e6976657273616c2d63616368652f6c6963656e7365)](https://packagist.org/packages/corneltek/universal-cache)

A Generic PHP Cache Interface with Cascade Caching.

DESCRIPTION
-----------

[](#description)

This package was inspired by a Perl module - Cache::Cascade.

> In a multiprocess, and especially a multiserver application caching is a very effective means of improving results.

> The tradeoff of increasing the scale of the caching is in added complexity. For example, caching in a FastMmap based storage is much slower than using a memory based cache, because pages must be locked to ensure that no corruption will happen. Likewise Memcached is even more overhead than FastMmap because it is network bound, and uses blocking IO (on the client side).

> This module attempts to make a transparent cascade of caches using several backends.

> The idea is to search from the cheapest backend to the most expensive, and depending on the options also cache results in the cheaper backends.

> The benefits of using a cascade are that if the chance of a hit is much higher in a slow cache, but checking a cheap cache is negligible in comparison, we may already have the result we want in the cheap cache. Configure your expiration policy so that there is approximately an order of magnitude better probability of cache hits (bigger cache) for each level of the cascade.

INSTALL
-------

[](#install)

```
composer require corneltek/universal-cache

```

### UniversalCache

[](#universalcache-1)

UniversalCache class provides a consistent interface to operate on different cache backend, you may put the fastest cache backend on the first position, so that you can fetch the cache very quickly when there is a fresh cache in the fastest storage.

```
use UniversalCache\ApcuCache;
use UniversalCache\FileSystemCache;
use UniversalCache\UniversalCache;

$cache = new UniversalCache([
    new ArrayCache, // Fetch cache without serialization if there is a request-wide cache exists.
    new ApcuCache('app_', 60), // Faster then file system cache.
    new FileSystemCache(__DIR__ . '/cache'),
]);
$cache->set('key', 'value');
$value = $cache->get('key');
```

### ApcuCache

[](#apcucache)

```
$cache = new UniversalCache\ApcuCache('app_', 3600); // 3600 = expiry time
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);
```

### ArrayCache

[](#arraycache)

ArrayCache implements a pure php based cache, the cache is not persistent between different request. However, it made the request-wide cache simple.

```
$cache = new UniversalCache\ArrayCache;
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);
```

### MemcacheCache

[](#memcachecache)

```
$cache = new UniversalCache\MemcacheCache([
    'servers' => [['localhost', 123123], ['server2',123123] ]
]);
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);
```

### RedisCache

[](#rediscache)

```
$cache = new UniversalCache\RedisCache($redisConnection);
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);
```

### FileSystemCache

[](#filesystemcache)

```
$serializer = new SerializerKit\JsonSerializer();
$cache = new UniversalCache\FileSystemCache(__DIR__ . '/cache', [
    'expiry' => 30,
    'serializer' => $serializer,
]);
```

Hacking
-------

[](#hacking)

Install dependencies

```
composer install --prefer-source

```

Install redis extension

```
phpbrew ext install github:phpredis/phpredis php7

```

Install memcached extension

```
phpbrew ext install github:php-memcached-dev/php-memcached php7 -- --disable-memcached-sasl

```

Install APCu extension

```
phpbrew ext install github:krakjoe/apcu

```

Be sure to enable apcu and cli mode

```
apc.enabled=1
apc.enable_cli=1

```

Run tests

```
phpunit

```

LICENSE
-------

[](#license)

This package is released under MIT license.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~234 days

Recently: every ~0 days

Total

6

Last Release

3629d ago

Major Versions

1.0.6 → 3.0.02016-06-10

PHP version history (3 changes)1.0.6PHP &gt;=5.3.0

3.0.0PHP &gt;=5.5.0

3.2.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cc34cde233b660869ff329ed8e20df611f75dfb61aab3e30889ac153d3e5e61?d=identicon)[c9s](/maintainers/c9s)

---

Top Contributors

[![c9s](https://avatars.githubusercontent.com/u/50894?v=4)](https://github.com/c9s "c9s (113 commits)")

### Embed Badge

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

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

###  Alternatives

[corneltek/assetkit

High performance asset manager.

531.4k3](/packages/corneltek-assetkit)[corneltek/configkit

Fast config toolkit, which provides super lightweight config accessor and loader.

1314.1k8](/packages/corneltek-configkit)[corneltek/genphp

421.3k3](/packages/corneltek-genphp)[corneltek/actionkit

181.5k](/packages/corneltek-actionkit)

PHPackages © 2026

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