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

ActiveLibrary[Caching](/categories/caching)

pluggit/cache
=============

A library to provide cache interface access to different backend caches

2.4.1(7y ago)141.9k↓50%2[2 PRs](https://github.com/CMProductions/cache/pulls)MITPHPPHP &gt;=5.5

Since Jul 18Pushed 2y ago19 watchersCompare

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

READMEChangelog (6)Dependencies (7)Versions (21)Used By (0)

Pluggit - Cache
===============

[](#pluggit---cache)

[![Build Status](https://camo.githubusercontent.com/f6fa8f3d46c00f6a0f34698b163521595da72434500cebf068d57044dbcb1c1d/68747470733a2f2f7472617669732d63692e6f72672f434d50726f64756374696f6e732f63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/CMProductions/cache)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4cb281fea481d8b25d25f2667f38a3c3590200f71dddc64773a7f94c8f22c5ee/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f434d50726f64756374696f6e732f63616368652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/CMProductions/cache/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/cc6e67e5635ef869df1fb55274683986eaac79549322752716bc311d7292e594/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f434d50726f64756374696f6e732f63616368652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/CMProductions/cache/?branch=master)

Provides an abstracion over most common user caches

TLDR;
-----

[](#tldr)

```
/** @var \Cmp\Cache\Cache $cache */
$cache = (new CacheBuilder)
  ->withLogging($psrLogger)
  ->withoutExceptions()
  ->withArrayCache()
  ->withRedisCacheFromParams($host, $port, $dbNumber)
  ->build();

// Set an item
$cache->set('foo', 'bar');

// Demand an item, throws an exception if not present
$bar = $cache->demand('foo');

// Get an item, if not present in any cache it will return the given default
$default = $cache->get('not found', 'default');

// Delete an item
$cache->delete('foo');

// Empty the cache
$cache->flush();

//Create a tagged cache
$taggedCache = $cache->tag('myTag');

//Set a tagged item
$taggedCache->set('key','value');

//Remove all tagged items
$taggedCache->flush();
```

The Cache interface
-------------------

[](#the-cache-interface)

The cache interface allows access to 10 methods:

- `set`
- `setAll`
- `has`
- `get`
- `getAll`
- `demand`
- `delete`
- `deleteAll`
- `flush`
- `tag`
- `appendList`
- `increase`

### Set

[](#set)

Use it to store values in the cache. You can make an item expire after a certain time by passing the `$timeToLive` parameter bigger than zero

***Note:*** Time to live must be an integer representing seconds

### SetAll

[](#setall)

Use it to store multiple values at one

### Has

[](#has)

Checks if an item is in the cache and has not expired

### Get

[](#get)

Tries to get an item from the cache, and if it's not there, it return a given default value

### GetAll

[](#getall)

Tries to get multiple items from the cache, if an item is not found, the key will be returned with a null

### Demand

[](#demand)

Tries to retrieve an item from the cache, if it's not present, it throws a `NotFoundException`

### Delete

[](#delete)

Deletes an item from the cache

### Delete All

[](#delete-all)

Deletes multiple items at once

### Flush

[](#flush)

It empties the cache

### Tag

[](#tag)

Creates a tagged cache instance. It works as a normal cache, but all the entries are put in a special bucket which you can flush.

Cache backends provided
-----------------------

[](#cache-backends-provided)

These are the current backend implementations:

- Redis
- Array (in memory)
- ChainCache

***Note:*** You can use the `CacheFactory` to easily build a cache object with one of the provided backends

### ChainCache

[](#chaincache)

The chain cache will accept one or more cache and tries all caches before failing

Cache backend decorator provided
--------------------------------

[](#cache-backend-decorator-provided)

- LoggerCache

### Logger Cache

[](#logger-cache)

It allows to log any exception thrown from the decorated cache. You can choose the silent mode to avoid throwing exceptions from the cache

**Note:** This decorator is used always when building a cache trough the builder, as it ensures that all exceptions thrown extend the base CacheException

Tags
----

[](#tags)

It is possible to use tags for grouping related objects. All three provided backends have this ability. To use it just request a new tagged cache instance using the tag() method, and then you'll be able to use it in the same way you use any other cache backend:

```
// Store one photo in the cache
$cache->set('photo.1', $photoOne);

// Store a set of photos and tag them
$cache->tag('photos')->set('photo.1', $taggedPhotoOne);
$cache->tag('photos')->set('photo.2', $taggedPhotoTwo);

// The photos are into different buckets
$cache->has('photo.1');                // true
$cache->has('photo.2')                 // false
$cache->tag('photos')->has('photo.1'); // true
$cache->tag('photos')->has('photo.2')  // true

// You can flush all items with the same tag at once
$cache->tag('photos')->flush();
$cache->has('photo.1');                // true
$cache->tag('photos')->has('photo.1'); // false
```

Pimple service provider
-----------------------

[](#pimple-service-provider)

The library includes a service provider for Pimple ^3.0 (included on Silex ^2.0) to easily register a cache

By default it will register an `ArrayCache` on the key `cache`

```
$pimple->register(new CacheServiceProvider());

/** @var LoggerCache $cache */
$cache = $pimple['cache'];

/** @var ArrayCache $cache */
$arrayCache = $pimple['cache']->getDecoratedCache();
```

### Options

[](#options)

- ***cache.backends***: an array of backends caches to use, if more than one is provided, the ChainCache will be used to wrap them all. Each backend option **must** have the key *backend*, the available options are:

    - `array`: It will create an ArrayCache (same as default)
    - `redis`: If you already have a redis connection, it can be passed on the key *connection* (if a string is used, the provider will try to get the service from the container. If the *connection* is not given, the provider will try to build a connection reading from the options array:
        - *host:* 127.0.0.1 by default
        - *port:* 6379 by default
        - *db:* 0 by default
        - *timeout:* 0.0 by default
    - `string`: If a string is given, the provider will try to get the service from the container, the service must implement then `Cmp\Cache\Cache` interface
    - `Cmp\Cache\Cache`: If an object implementing the Cache interface is given, it will be used directly
- ***cache.exceptions***: a boolean, true by default. If is set to true, the cache will be throw exceptions, if false, no exceptions will be thrown.
- ***cache.logging***: It allows to log exceptions thrown by the cache system. it accepts an array, with the following options:

    - `logger`: And instance of an logger implementing the Psr\\LoggerInterface
    - `log_level`: The log level to use for logging the exceptions, 'alert' by default. Must be one of the valid levels defined at Psr\\LogLevel

**Examples:**

```
// Redis from parameters
$pimple->register(new PimpleCacheProvider(), ['cache.backends' => [
    ['backend' => 'redis', 'host' => '127.0.0.1', 'port' => 6379, 'db' => 1, 'timeout' => 2.5]
]]);

// ArrayCache + Redis from existing connection
$pimple->register(new PimpleCacheProvider(), ['cache.backends' => [
    ['backend' => 'array']
    ['backend' => 'redis', 'connection' => $redisConnection,]
]]);

// ArrayCache + Redis from a service registered in the container
$pimple->register(new PimpleCacheProvider(), ['cache.backends' => [
    ['backend' => 'array']
    ['backend' => 'redis', 'connection' => 'redis.connection']
]]);

// Chain caches with logging and muted exceptions
$pimple->register(new PimpleCacheProvider(), [
    'cache.backends'   => [
        ['backend' => 'array'],
        ['backend' => 'custom_cache_service_key'],
    ],
    'cache.exceptions' => false,
    'cache.logging'    => ['logger' => $psrLogger, 'log_level' => PsrLevel::CRITICAL],
]);
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 72.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 ~68 days

Recently: every ~186 days

Total

15

Last Release

2636d ago

Major Versions

1.1.0 → 2.0.0-beta2016-07-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/2595584d57cbf851b56dc1935d9e34d96045fc7b4ca3c64058caa3ed5e3fb504?d=identicon)[techCMP](/maintainers/techCMP)

---

Top Contributors

[![hmoragrega](https://avatars.githubusercontent.com/u/3494001?v=4)](https://github.com/hmoragrega "hmoragrega (40 commits)")[![marcrubiocmp](https://avatars.githubusercontent.com/u/17856285?v=4)](https://github.com/marcrubiocmp "marcrubiocmp (8 commits)")[![carlosas-cmp](https://avatars.githubusercontent.com/u/38425287?v=4)](https://github.com/carlosas-cmp "carlosas-cmp (3 commits)")[![eleracmp](https://avatars.githubusercontent.com/u/35228903?v=4)](https://github.com/eleracmp "eleracmp (2 commits)")[![jmartinmad](https://avatars.githubusercontent.com/u/17850794?v=4)](https://github.com/jmartinmad "jmartinmad (2 commits)")

###  Code Quality

TestsBehat

### Embed Badge

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

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

###  Alternatives

[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k348.9M2.5k](/packages/symfony-cache)[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)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)[neos/cache

Neos Cache Framework

102.0M31](/packages/neos-cache)[ethanhann/redisearch-php

239113.6k1](/packages/ethanhann-redisearch-php)

PHPackages © 2026

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