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

ActiveLibrary[Caching](/categories/caching)

anik/cache
==========

v2.0(2y ago)499MITPHPPHP ^8.0

Since Mar 30Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

anik/cache [![codecov](https://camo.githubusercontent.com/fdf79135b65e3293ab21d2ea18f4a769c35a9851804faffc9d66e0dcd0b27ba8/68747470733a2f2f636f6465636f762e696f2f67682f7373692d616e696b2f63616368652f67726170682f62616467652e7376673f746f6b656e3d4f55375852464a515948)](https://codecov.io/gh/ssi-anik/cache)[![PHP Version Require](https://camo.githubusercontent.com/06a09f319876214c4b83ee5615c2aaa765c4107dc410707d314e21158072d05b/687474703a2f2f706f7365722e707567782e6f72672f616e696b2f63616368652f726571756972652f706870)](//packagist.org/packages/anik/cache)[![Latest Stable Version](https://camo.githubusercontent.com/4503e526a728926262b65b7a3bd49dbacd19acc794a0cae02d2e5fa5dd9aa3ca/68747470733a2f2f706f7365722e707567782e6f72672f616e696b2f63616368652f76)](//packagist.org/packages/anik/cache)
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#anikcache)

[anik/cache](https://packagist.org/packages/anik/cache) contains the implementation of [PSR-6 - Caching Interface](https://www.php-fig.org/psr/psr-6/) &amp; [PSR-16 - Common Interface for Caching Libraries](https://www.php-fig.org/psr/psr-16/)with

- Null Cache
- In-Memory/Runtime/Array cache

Use-case
--------

[](#use-case)

- When consuming a library that requires psr cache, and you don't want to use cache for some reason.
- When developing a library and developer may not provide the cache, and you don't want to do the if...else check.

```
if (!is_null($this->cache)){
    $this->cache->set($key,$value,$ttl);
}

if (!is_null($this->cache)){
    $this->cache->get($key)
}
```

Documentation
=============

[](#documentation)

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

[](#installation)

To install the package, run

> composer require anik/cache

Usage
-----

[](#usage)

### InMemoryPool &amp; NullPool

[](#inmemorypool--nullpool)

All the \***Pool** classes implement `CacheItemPoolInterface` interface defined in **PSR-6**. So, the following methods are available

```
use Psr\Cache\CacheItemInterface;

public function getItem(string $key): CacheItemInterface;
public function getItems(array $keys): CacheItemInterface[];
public function hasItem(string $key): bool;
public function clear(): bool;
public function deleteItem(string $key): bool;
public function deleteItems(array $keys): bool;
public function save(CacheItemInterface $item): bool;
public function saveDeferred(CacheItemInterface $item): bool;
public function commit(): bool;
```

### Item

[](#item)

The item class implements `\Anik\Cache\Contracts\CacheItemInterface`, an extension of `\Psr\Cache\CacheItemInterface`. So, the following methods are available.

```
public function getKey(): string;
public function get(): mixed;
public function isHit(): bool;
public function set(mixed $value): static;
public function expiresAt(\DateTimeInterface|null $expiration): static;
public function expiresAfter(\DateInterval|int|null$time): static;

public function getExpiration(): ?int;
public function getValue(): mixed;
```

#### Caveat

[](#caveat)

When saving data to the cache using **save** or **saveDeferred** methods, the `\Anik\Cache\Contracts\CacheItemInterface`should be passed to those methods.

### PoolAdapter

[](#pooladapter)

The **PoolAdapter** class implements both `CacheItemPoolInterface` (PSR-6), `CacheInterface` (PSR-16) interfaces. So the following methods are available.

```
use Psr\Cache\CacheItemInterface;

public function getItem(string $key): CacheItemInterface;
public function getItems(array $keys): CacheItemInterface[];
public function hasItem(string $key): bool;
public function clear(): bool;
public function deleteItem(string $key): bool;
public function deleteItems(array $keys): bool;
public function save(CacheItemInterface $item): bool;
public function saveDeferred(CacheItemInterface $item): bool;
public function commit(): bool;

public function get(string $key, mixed $default = null): mixed;
public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool;
public function delete(string $key): bool;
public function clear(): bool;
public function getMultiple(iterable $keys, mixed $default = null): iterable;
public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool;
public function deleteMultiple(iterable $keys): bool;
public function has(string $key): bool;
```

### Example

[](#example)

### NullPool/InMemoryPool

[](#nullpoolinmemorypool)

```
use Anik\Cache\Item;
use Anik\Cache\Pool\NullPool;

$pool = new NullPool();
// $pool = new NullPool($defaultReturnValue);
// $pool = new InMemoryPool();

// Item to store
$item = new Item('key-1', 'value-1');
// $item = new Item('key-2', 'value-2');

// Item expiration
// $item->expiresAfter(10);
// $item->expiresAt(($now = new DateTimeImmutable())->modify('+100 seconds'))

// save item
$pool->save($item);

// save deferred
$pool->saveDeferred($item);
$pool->commit();

// get item
$item = $pool->getItem('key-1');
$item->isHit();
$item->get();

// get multiple items
$pool->getItems(['key-1', 'key-2']);

// has item
$pool->hasItem('key-1');

// delete item
$pool->deleteItem('key-1');

// delete multiple items
$pool->deleteItems(['key-1', 'key-2']);

// clear pool
$pool->clear();
```

### PoolAdapter

[](#pooladapter-1)

```
use Anik\Cache\Item;
use Anik\Cache\Pool\NullPool;
use Anik\Cache\PoolAdapter;

// pass the type of pool you want to use
$adapter = new PoolAdapter(new NullPool());
// $adapter = new PoolAdapter(new NullPool($defaultReturnValue));
// $adapter = new PoolAdapter(new InMemoryPool());

// can achieve the same using the helper methods
// $adapter = null_cache();
// $adapter = null_cache($defaultReturnValue);
// $adapter = in_memory_cache();

// Item to store
$item = new Item('key-1', 'value-1');
// $item = new Item('key-2', 'value-2');

// Item expiration
// $item->expiresAfter(10);
// $item->expiresAt(($now = new DateTimeImmutable())->modify('+100 seconds'))

// save/save deferred item
$adapter->save($item);
$adapter->saveDeferred($item);
$adapter->commit();
// Otherwise,
$adapter->set('key-3', 'value-3');

// get item
$item = $adapter->getItem('key-1');
$item->isHit();
$item->get();
// Otherwise
$adapter->get('key-3');

// get multiple items
$adapter->getItems(['key-1', 'key-2']);

// Otherwise
$adapter->getMultiple(['key-1', 'key-4'], 'default-value');

// has item
$adapter->hasItem('key-1');
// otherwise
$adapter->has('key-1');

// delete item
$adapter->deleteItem('key-1');

// delete multiple items
$adapter->deleteItems(['key-1', 'key-2']);
// Otherwise
$adapter->deleteMultiple(['key-1', 'key-2']);

// clear pool
$adapter->clear();
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 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 ~0 days

Total

2

Last Release

780d ago

Major Versions

v1.0 → v2.02024-03-30

PHP version history (2 changes)v1.0PHP ^7.3

v2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7180f132fd7bfbbec2083528838f87996e01a6165ef50e58e2f3fcfccda1a834?d=identicon)[ssi-anik](/maintainers/ssi-anik)

---

Top Contributors

[![ssi-anik](https://avatars.githubusercontent.com/u/2676602?v=4)](https://github.com/ssi-anik "ssi-anik (25 commits)")

---

Tags

caching-interfacein-memory-cachenull-cachephppsr-16psr-16-simple-cachepsr-6psr-6-caching-interfacepsr-cachesimple-cachepsr-16psr-6psr-cachepsr-simple-cachearray cachesimple-cache-implementationcache-contract-implementationnull-cachein-memory-cacheruntime-cache

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[matthiasmullie/scrapbook

Scrapbook is a PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APCu, SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

3212.5M32](/packages/matthiasmullie-scrapbook)[cache/simple-cache-bridge

A PSR-6 bridge to PSR-16. This will make any PSR-6 cache compatible with SimpleCache.

423.1M27](/packages/cache-simple-cache-bridge)[apix/simple-cache

The PSR-16 extension to Apix-Cache.

1017.4k](/packages/apix-simple-cache)[codeigniter4/cache

PSR-6 and PSR-16 Cache Adapters for CodeIgniter 4

1320.1k](/packages/codeigniter4-cache)

PHPackages © 2026

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