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

ActiveLibrary[Caching](/categories/caching)

vectorface/cache
================

Simple cache classes

v0.7.0(10mo ago)914.8k↓34.6%2[1 issues](https://github.com/Vectorface/cache/issues)MITPHPPHP &gt;=8.0.0CI passing

Since Jan 10Pushed 10mo ago8 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (16)Used By (0)

Cache
=====

[](#cache)

[![Build Status](https://camo.githubusercontent.com/4e4d8bc6a31fb60a4d51de3d9ed2b7da4ca861e4a204af28b01f45dab0fd343e/68747470733a2f2f7472617669732d63692e6f72672f566563746f72666163652f63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Vectorface/cache)[![Code Coverage](https://camo.githubusercontent.com/4289831bf9ebd0306d98787b19686707871971f2bfc11a609d86f66135686831/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f566563746f72666163652f63616368652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Vectorface/cache/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/a39cab1edbf7d66e4c51b934acacad0c11ba5731c18efcea09e98a105a38c117/68747470733a2f2f706f7365722e707567782e6f72672f766563746f72666163652f63616368652f762f737461626c652e737667)](https://packagist.org/packages/vectorface/cache)[![License](https://camo.githubusercontent.com/ef947b72ff0a62a65f4e791b3902d02bc022abb805d50bd19db29b8c996648c6/68747470733a2f2f706f7365722e707567782e6f72672f766563746f72666163652f63616368652f6c6963656e73652e737667)](https://packagist.org/packages/vectorface/cache)

This is a simple cache library. It exposes several caching mechanisms (with different semantics), along with support for adapting to a PSR-16 compatible interface, and atomic counters. Nothing fancy.

Interface
---------

[](#interface)

The cache interface exposes get and set methods, which do exactly what you'd expect from a cache:

```
use Vectorface\Cache\PHPCache;

// PHPCache is a trivial array-backed cache.
$cache = new PHPCache();
$cache->get("foo"); // null, because we just created this cache.
$cache->get("foo", "dflt"); // "dflt"; same as above, but with our own default
$cache->set("foo", "bar"); // returns true if set. This cache always succeeds.
$cache->get("foo"); // "bar", because we just set it.
```

The interface supports optional time-to-live (expiry) where supported by the underlying cache type. The interface also provides `delete`, `clean`, and `flush` methods to delete one entry, all expired entries, and all entries (respectively).

Available Implementations
-------------------------

[](#available-implementations)

- `APCCache`: APC or APCu.
- `MCCache`: Memcache
- `RedisCache`: Redis, using either the [phpredis](https://github.com/phpredis/phpredis) extension or the [php-redis-client](https://github.com/cheprasov/php-redis-client) library
- `NullCache`: A blackhole for your data
- `PHPCache`: Stores values in a local variable, for one script execution only.
- `SQLCache`: Values stored in an SQL table, accessed via PDO.
- `TempFileCache`: Store values in temporary files. Does not support atomic counting.
- `TieredCache`: Layer any of the above caches on top of each other to form a hybrid cache. Does not support atomic counting.

Real-World Use
--------------

[](#real-world-use)

Why would you want to use this? It makes it almost trivial to switch your underlying cache implementation without any code changes. This can be especially useful for testing.

```
use Vectorface\Cache\APCCache;
use Vectorface\Cache\PHPCache;
use Vectorface\Cache\TempFileCache;

// Memcache and SQL-based caches also work, but aren't as good as examples.
$caches = [new APCCache(), new PHPCache(), new TempFileCache()];
foreach ($caches as $cache) {
    // Look ma! Same interface!
    $cache->set('foo', 'bar');
    $cache->get('foo');
}
```

### Atomic Counters

[](#atomic-counters)

A common use of caches are to implement atomic counting, i.e. incrementing or decrementing by some amount. Atomicity is important for reliability in distributed environments to avoid race conditions.

Not all cache implementations in this library support atomic counting, because it either isn't possible or doesn't make sense in that context.

```
use Vectorface\Cache\APCCache;
use Vectorface\Cache\AtomicCounter;

$cache = new APCCache();
assert($cache instanceof AtomicCounter);

// Can increment and decrement by key, defaults to steps of 1
assert($cache->increment("counter") === 1);
assert($cache->increment("counter") === 2);
assert($cache->decrement("counter") === 1);

// Can step by arbitrary amounts
assert($cache->increment("counter", 5) === 6);
assert($cache->decrement("counter", 2) === 4);
```

### Tiered Caching

[](#tiered-caching)

Another particularly useful feature is the ability to stack caches. You can put fast caches in front of successively slower caches, presumably where the fast caches will have less storage and evict items used less often.

```
use Vectorface\Cache\APCCache;
use Vectorface\Cache\MCCache;
use Vectorface\Cache\TempFileCache;
use Vectorface\Cache\TieredCache;

$memcache = new Memcache();
$memcache->addServer("127.0.0.1");
$cache = new TieredCache([
    new APCCache(),
    new MCCache($memcache),
    new TempFileCache(),
]);

$cache->get("foo"); // Tries all caches in sequence until one succeeds. Fails if none succeed.
$cache->set("foo", "bar"); // Sets a value in all caches.
$cache->get("foo"); // Tries all caches in sequence. The fastest should succeed and return quickly.
```

### PSR-16 Support

[](#psr-16-support)

If you need interoperability with other tooling that support PSR-16 SimpleCache, you may use the `SimpleCacheAdapter` class which can wrap any of the cache implementations in this library.

```
use Psr\SimpleCache\CacheInterface;
use Vectorface\Cache\PHPCache;
use Vectorface\Cache\SimpleCacheAdapter;

$psr16Cache = new SimpleCacheAdapter(new PHPCache());

assert($psr16Cache instanceof CacheInterface);
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance51

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 81.7% 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 ~294 days

Recently: every ~348 days

Total

14

Last Release

326d ago

PHP version history (5 changes)v0.0.1PHP &gt;=5.3.0

v0.1.0PHP ^7.0

v0.2.1PHP &gt;=7.0.0

v0.4.0PHP &gt;=7.3.0

v0.5.0PHP &gt;=8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/df4da5988e7543fce193f4554a6bb30fda64a716fb922cddd36612f82ab7e5a3?d=identicon)[janderson](/maintainers/janderson)

![](https://www.gravatar.com/avatar/7a6bd4b7a52a1ed056c6d597c4124a62da080137edd42cc34355ac2c28e4a154?d=identicon)[francislavoie](/maintainers/francislavoie)

---

Top Contributors

[![jdpanderson](https://avatars.githubusercontent.com/u/4468291?v=4)](https://github.com/jdpanderson "jdpanderson (58 commits)")[![francislavoie](https://avatars.githubusercontent.com/u/2111701?v=4)](https://github.com/francislavoie "francislavoie (13 commits)")

---

Tags

cache

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[cache/adapter-common

Common classes for PSR-6 adapters

11124.4M38](/packages/cache-adapter-common)[cache/cache

Library of all the php-cache adapters

2712.7M22](/packages/cache-cache)[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1076.9M130](/packages/laminas-laminas-cache)[neos/cache

Neos Cache Framework

102.0M31](/packages/neos-cache)[graham-campbell/bounded-cache

A Bounded TTL PSR-16 Cache Implementation

101.9M6](/packages/graham-campbell-bounded-cache)[mmamedov/page-cache

PageCache is a lightweight PHP library for full page cache. It uses various strategies to differentiate among separate versions of the same page.

7912.7k1](/packages/mmamedov-page-cache)

PHPackages © 2026

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