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

ActiveLibrary[Caching](/categories/caching)

itsoneiota/cache
================

One iota Cache library.

1.17(6y ago)15.3k11proprietaryPHPPHP &gt;=5.5CI failing

Since Nov 1Pushed 6y ago3 watchersCompare

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

READMEChangelogDependencies (5)Versions (23)Used By (1)

One iota Cache Library
======================

[](#one-iota-cache-library)

Overview
--------

[](#overview)

A simple interface to cache sources.

The `Cache` class wraps a `Memcached` instance, adding key and value mapping, and default expiry times.

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

[](#installation)

The best way to autoload this package and its dependencies is to include the standard Composer autoloader, `vendor/autoload.php`.

Testing
-------

[](#testing)

The library's suite of unit tests can be run by calling `vendor/bin/phpunit` from the root of the repository.

Basic Usage
-----------

[](#basic-usage)

```
use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc);

$cache->set('foo', 'bar'); // Caches a value of 'bar' against the key of 'foo'.
$cache->get('foo'); // Returns 'bar'.

```

Prefixing Cache Keys
--------------------

[](#prefixing-cache-keys)

If you wish to avoid cache key collisions, you can initialise your cache with a key prefix, this will be added to all keys when getting, setting and deleting. For example:

```
use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc, 'myStore');

$cache->set('foo', 'bar'); // Caches a value of 'bar' against the key of 'myStore.foo'.
$cache->get('foo'); // Returns 'bar'.

```

Default Expiry Times
--------------------

[](#default-expiry-times)

When creating a cache, you can specify a default time to live that can be used when adding and setting. This can be overridden when adding and setting by specifying an explicit expiry time.

```
use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc, 'myStore', 120);

$cache->set('foo', 'bar'); // Caches for 2 minutes (the default).
$cache->set('bat', 'baz', 30); // Caches for 30 seconds.

```

Encrypting Cache Contents
-------------------------

[](#encrypting-cache-contents)

`SecureCache` is a subclass of `Cache` that encrypts its contents using two-way encryption.

```
use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new SecureCache($mc, 'myTopSecretEncryptionKey');

```

If you need to prefix keys in SecureCache, you can always call `$cache->setKeyPrefix('myPrefix')`.

Bonus Caches (Cacheback)
------------------------

[](#bonus-caches-cacheback)

### `InMemoryCacheFront`

[](#inmemorycachefront)

If you're likely to make several calls to a cache within a request, possibly to the same value, `InMemoryCacheFront` can prevent unnecessary network calls to the Memcached server, by providing a read- and write-through cache on top of a `Cache` instance. The number of items held in memory is limited to 100 by default, but that can be changed with a constructor argument.

```
use \itsoneiota\cache;

$mc = new \Memcached();
// Configure memcached…

$cache = new Cache($mc, 'myStore', 120);

$superFastCache = new InMemoryCacheFront($cache, 1000); // Store 1000 items in local memory.

```

### `InMemoryCache`

[](#inmemorycache)

If you need to simulate a cache, without a Memcached server, `InMemoryCache` will do the job. It looks just like a `Cache`, but it holds everything in a plain-old PHP array.

### `MockCache`

[](#mockcache)

For testing purposes, `MockCache` simulates a cache, and allows you to check that values have been set, and what their expiry times are, without having to go through all the hassle of using PHPUnit mocks. `getExpiration()` allows you to check the expiration of a key. `timePasses()` allows you to simulate the passage of time, advancing by a given number of seconds and expiring cache items accordingly.

```
use \itsoneiota\cache;

$cache = new MockCache();

$cache->set('foo', 'bar', 60);
$cache->get('foo'); // Returns 'bar'.

$cache->timePasses(61);

$cache->get('foo'); // Returns NULL.

```

To Do…
------

[](#to-do)

Things I might add, soon-ish:

- Check-and-set operations
- Cache pile-on prevention

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 69.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 ~75 days

Recently: every ~45 days

Total

18

Last Release

2203d ago

### Community

Maintainers

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

---

Top Contributors

[![rossmcf](https://avatars.githubusercontent.com/u/94686?v=4)](https://github.com/rossmcf "rossmcf (25 commits)")[![jwrodway](https://avatars.githubusercontent.com/u/43041629?v=4)](https://github.com/jwrodway "jwrodway (4 commits)")[![silvanoceccacci](https://avatars.githubusercontent.com/u/64652259?v=4)](https://github.com/silvanoceccacci "silvanoceccacci (3 commits)")[![jrodway](https://avatars.githubusercontent.com/u/39333046?v=4)](https://github.com/jrodway "jrodway (2 commits)")[![mattyev87](https://avatars.githubusercontent.com/u/11663120?v=4)](https://github.com/mattyev87 "mattyev87 (1 commits)")[![pbartlett-oi](https://avatars.githubusercontent.com/u/17140503?v=4)](https://github.com/pbartlett-oi "pbartlett-oi (1 commits)")

---

Tags

cache

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[cache/predis-adapter

A PSR-6 cache implementation using Redis (Predis). This implementation supports tags

272.6M13](/packages/cache-predis-adapter)[sobstel/metaphore

PHP cache slam defense using a semaphore to prevent dogpile effect (aka clobbering updates or stampending herd).

100179.4k1](/packages/sobstel-metaphore)[contributte/redis

Redis client integration into Nette framework

181.6M2](/packages/contributte-redis)[pstaender/silverstripe-redis-cache

Enables Redis cache for SilverStripe

1199.1k](/packages/pstaender-silverstripe-redis-cache)[abouvier/slim-redis-cache

Redis cache middleware for Slim framework

172.0k](/packages/abouvier-slim-redis-cache)[bnomei/kirby3-redis-cachedriver

Advanced Redis cache-driver with in-memory store, transactions and preloading

101.7k](/packages/bnomei-kirby3-redis-cachedriver)

PHPackages © 2026

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