PHPackages                             desarrolla2/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. [Database &amp; ORM](/categories/database)
4. /
5. desarrolla2/cache

ActiveLibrary[Database &amp; ORM](/categories/database)

desarrolla2/cache
=================

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported.

v3.0.2(4y ago)1322.5M—2.1%3820MITPHPPHP &gt;=7.2.0

Since Oct 23Pushed 3y ago7 watchersCompare

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

READMEChangelog (2)Dependencies (8)Versions (30)Used By (20)

Desarolla2 Cache
================

[](#desarolla2-cache)

A **simple cache** library, implementing the [PSR-16](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) standard using **immutable** objects.

[![life-is-hard-cache-is](https://user-images.githubusercontent.com/100821/41566888-ecd60cde-735d-11e8-893f-da42b2cd65e7.jpg)](https://user-images.githubusercontent.com/100821/41566888-ecd60cde-735d-11e8-893f-da42b2cd65e7.jpg)

Caching is typically used throughout an applicatiton. Immutability ensure that modifying the cache behaviour in one location doesn't result in unexpected behaviour due to changes in unrelated code.

*Desarolla2 Cache aims to be the most complete, correct and best performing PSR-16 implementation available.*

[![Latest version](https://camo.githubusercontent.com/56f6af2ded9c3521126089c89625f8259ea040b9225f599401c3048d13ddab51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465736172726f6c6c61322f43616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/desarrolla2/cache)[![Latest version](https://camo.githubusercontent.com/35d906f8304d0f243646bf942ff0eb02cec99d9a53d42258b0a4f777b33ad659/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6465736172726f6c6c61322f43616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/desarrolla2/cache)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://hassankhan.mit-license.org)[![Build Status](https://github.com/desarrolla2/Cache/workflows/PHP/badge.svg)](https://github.com/desarrolla2/Cache/actions)[![Coverage Status](https://camo.githubusercontent.com/8b75d59cc26521bb16738de3e7d62169b449e0b8a41b0b9b8ad352a38c5ba5c2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6465736172726f6c6c61322f43616368652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/desarrolla2/cache)[![Quality Score](https://camo.githubusercontent.com/a18185a2f68d3af33e93a0b2eac5cafeb11302700303d08e6cd02a31295677b6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6465736172726f6c6c61322f63616368652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/desarrolla2/cache)[![Total Downloads](https://camo.githubusercontent.com/366fe80fa54ce7955b86df9d13f2eea00ccde458bc50b9cce908a4978786c56c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465736172726f6c6c61322f63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/desarrolla2/cache)[![Today Downloads](https://camo.githubusercontent.com/52ebc47bff2ff93093171577a7010ae55bf698246b2f4c1ab85d6410c4b4e9fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f6465736172726f6c6c61322f63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/desarrolla2/cache)[![Gitter](https://camo.githubusercontent.com/82b37b704e2e79c5d50f45f6cf0aab5873f32ffcca6c38864d72b1a66c2ba48c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4749545445522d4a4f494e253230434841542532302545322538362539322d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://gitter.im/desarrolla2/Cache?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

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

[](#installation)

```
composer require desarrolla2/cache

```

Usage
-----

[](#usage)

```
use Desarrolla2\Cache\Memory as Cache;

$cache = new Cache();

$value = $cache->get('key');

if (!isset($value)) {
    $value = do_something();
    $cache->set('key', $value, 3600);
}

echo $value;
```

Adapters
--------

[](#adapters)

- [Apcu](docs/implementations/apcu.md)
- [File](docs/implementations/file.md)
- [Memcached](docs/implementations/memcached.md)
- [Memory](docs/implementations/memory.md)
- [MongoDB](docs/implementations/mongodb.md)
- [Mysqli](docs/implementations/mysqli.md)
- [NotCache](docs/implementations/notcache.md)
- [PhpFile](docs/implementations/phpfile.md)
- [Predis](docs/implementations/predis.md)
- [Redis](docs/implementations/redis.md)

The following implementation allows you to combine cache adapters.

- [Chain](docs/implementations/chain.md)

### Options

[](#options)

You can set options for cache using the `withOption` or `withOptions` method. Note that all cache objects are immutable, setting an option creates a new object.

#### TTL

[](#ttl)

All cache implementations support the `ttl` option. This sets the default time (in seconds) that cache will survive. It defaults to one hour (3600 seconds).

Setting the TTL to 0 or a negative number, means the cache should live forever.

Methods
-------

[](#methods)

### PSR-16 methods

[](#psr-16-methods)

Each cache implementation has the following `Psr\SimpleCache\CacheInterface`methods:

##### `get(string $key [, mixed $default])`

[](#getstring-key--mixed-default)

Retrieve the value corresponding to a provided key

##### `has(string $key)`

[](#hasstring-key)

Retrieve the if value corresponding to a provided key exist

##### `set(string $key, mixed $value [, int $ttl])`

[](#setstring-key-mixed-value--int-ttl)

Add a value to the cache under a unique key

##### `delete(string $key)`

[](#deletestring-key)

Delete a value from the cache

##### `clear()`

[](#clear)

Clear all cache

##### `getMultiple(array $keys)`

[](#getmultiplearray-keys)

Obtains multiple cache items by their unique keys

##### `setMultiple(array $values [, int $ttl])`

[](#setmultiplearray-values--int-ttl)

Persists a set of key =&gt; value pairs in the cache

##### `deleteMultiple(array $keys)`

[](#deletemultiplearray-keys)

Deletes multiple cache items in a single operation

### Additional methods

[](#additional-methods)

The `Desarrolla2\Cache\CacheInterface` also has the following methods:

##### `withOption(string $key, string $value)`

[](#withoptionstring-key-string-value)

Set option for implementation. Creates a new instance.

##### `withOptions(array $options)`

[](#withoptionsarray-options)

Set multiple options for implementation. Creates a new instance.

##### `getOption(string $key)`

[](#getoptionstring-key)

Get option for implementation.

Packers
-------

[](#packers)

Cache objects typically hold a `Desarrolla2\Cache\Packer\PackerInterface`object. By default, packing is done using `serialize` and `unserialize`.

Available packers are:

- `SerializePacker` using `serialize` and `unserialize`
- `JsonPacker` using `json_encode` and `json_decode`
- `NopPacker` does no packing
- `MongoDBBinaryPacker` using `serialize` and `unserialize` to store as [BSON Binary](http://php.net/manual/en/class.mongodb-bson-binary.php)

#### PSR-16 incompatible packers

[](#psr-16-incompatible-packers)

The `JsonPacker` does not fully comply with PSR-16, as packing and unpacking an object will probably not result in an object of the same class.

The `NopPacker` is intended when caching string data only (like HTML output) or if the caching backend supports structured data. Using it when storing objects will might give unexpected results.

Contributors
------------

[](#contributors)

[![Daniel González](https://avatars1.githubusercontent.com/u/661529?v=3&s=80)](https://github.com/desarrolla2)Twitter: [@desarrolla2](https://twitter.com/desarrolla2)
[![Arnold Daniels](https://avatars3.githubusercontent.com/u/100821?v=3&s=80)](https://github.com/jasny)Twitter: [@ArnoldDaniels](https://twitter.com/ArnoldDaniels)

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community40

Growing community involvement

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 56.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 ~153 days

Recently: every ~217 days

Total

26

Last Release

1110d ago

Major Versions

1.8.1 → v2.0.02015-10-27

1.8.3 → 3.x-dev2018-06-23

PHP version history (5 changes)v1.0.0PHP &gt;=5.3.0

1.8.1PHP &gt;=5.3.3

v2.0.0PHP &gt;=5.4.0

3.x-devPHP &gt;=7.1.0

v3.0.1PHP &gt;=7.2.0

### Community

Maintainers

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

---

Top Contributors

[![desarrolla2](https://avatars.githubusercontent.com/u/661529?v=4)](https://github.com/desarrolla2 "desarrolla2 (124 commits)")[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (66 commits)")[![poratuk](https://avatars.githubusercontent.com/u/12087528?v=4)](https://github.com/poratuk "poratuk (5 commits)")[![ragboyjr](https://avatars.githubusercontent.com/u/1975857?v=4)](https://github.com/ragboyjr "ragboyjr (5 commits)")[![gresakg](https://avatars.githubusercontent.com/u/2828923?v=4)](https://github.com/gresakg "gresakg (3 commits)")[![bryantAXS](https://avatars.githubusercontent.com/u/367604?v=4)](https://github.com/bryantAXS "bryantAXS (3 commits)")[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (1 commits)")[![lukasz-schab](https://avatars.githubusercontent.com/u/1589950?v=4)](https://github.com/lukasz-schab "lukasz-schab (1 commits)")[![nike-17](https://avatars.githubusercontent.com/u/676670?v=4)](https://github.com/nike-17 "nike-17 (1 commits)")[![ozziest](https://avatars.githubusercontent.com/u/2325140?v=4)](https://github.com/ozziest "ozziest (1 commits)")[![pranavpc](https://avatars.githubusercontent.com/u/5462262?v=4)](https://github.com/pranavpc "pranavpc (1 commits)")[![scottrobertson](https://avatars.githubusercontent.com/u/68361?v=4)](https://github.com/scottrobertson "scottrobertson (1 commits)")[![sunspikes](https://avatars.githubusercontent.com/u/75611?v=4)](https://github.com/sunspikes "sunspikes (1 commits)")[![ajbdev](https://avatars.githubusercontent.com/u/572055?v=4)](https://github.com/ajbdev "ajbdev (1 commits)")[![woutersamaey](https://avatars.githubusercontent.com/u/71019?v=4)](https://github.com/woutersamaey "woutersamaey (1 commits)")[![asmecher](https://avatars.githubusercontent.com/u/200411?v=4)](https://github.com/asmecher "asmecher (1 commits)")[![benswinburne](https://avatars.githubusercontent.com/u/1208977?v=4)](https://github.com/benswinburne "benswinburne (1 commits)")[![echernyavskiy](https://avatars.githubusercontent.com/u/1200767?v=4)](https://github.com/echernyavskiy "echernyavskiy (1 commits)")[![gries](https://avatars.githubusercontent.com/u/417823?v=4)](https://github.com/gries "gries (1 commits)")[![itn3rd77](https://avatars.githubusercontent.com/u/2655169?v=4)](https://github.com/itn3rd77 "itn3rd77 (1 commits)")

---

Tags

mysqlrediscachesimple-cachepsr-16filememcachedapcuapcmongomemcache

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-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)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[arvenil/ninja-mutex

Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking

1873.7M27](/packages/arvenil-ninja-mutex)[endeveit/cache

Simple caching library with support for tags.

1711.1k](/packages/endeveit-cache)

PHPackages © 2026

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