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

ActiveLibrary[Caching](/categories/caching)

webiny/cache
============

Webiny Cache Component

v1.6.1(8y ago)13483MITPHPPHP ^7

Since Sep 19Pushed 8y ago8 watchersCompare

[ Source](https://github.com/Webiny/Cache)[ Packagist](https://packagist.org/packages/webiny/cache)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-cache/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (6)Versions (23)Used By (3)

Cache Component
===============

[](#cache-component)

`Cache` component give you ability to store different information into memory for a limited time.

Install the component
---------------------

[](#install-the-component)

The best way to install the component is using Composer.

```
composer require webiny/cache
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/cache).

Supported drivers
-----------------

[](#supported-drivers)

The cache component supports following cache drivers:

- `APC` ()
    - only available in PHP 5.4, from PHP 5.5 APC is not supported
- `Couchbase` ()
- `Memcache` ()
- `Redis` ()

If you are not sure which driver to use, we suggest `Memcache`.

Based on the selected driver, you'll have to pass different options to the constructor.

Requirements
------------

[](#requirements)

The default bridged library is `Memory` by `Jamm` (). It is required that you add this library to the `ClassLoader` :

```
    \Webiny\Components\ClassLoader::getInstance()->registerMap(['Jamm\Memory' => 'path to memory lib']);
```

For example:

```
    // APC
    $cache = \Webiny\Component\Cache\Cache::APC('cache-id');

    // Couchbase
    $cache = \Webiny\Component\Cache\Cache::Couchbase('CacheService', 'username', 'password', 'bucket', '127.0.0.1:8091');

    // Memcache
    $cache = \Webiny\Component\Cache\Cache::Memcache('CacheService', 'localhost', 11211);

    // Redis
    $cache = \Webiny\Component\Cache\Cache::Redis('CacheService', 'localhost', 6379);
```

Common operations
-----------------

[](#common-operations)

Once you have created your `Cache` instance, you can start using your cache. The cache methods are the same, no matter which driver you use:

```
    // write to cache
    $cache->save('myKey', 'some value', 600, ['tag1', 'tag2']);

    // read from cache
    $cache->read('myKey');

    // delete from cache
    $cache->delete('myKey');

    // delete by tag
    $cache->deleteByTag(['tag1']);
```

Cache config
------------

[](#cache-config)

The preferred way of defining cache drivers is creating them inside your the config file of your application.

```
    Cache:
      TestCache:
        Factory: "\Webiny\Component\Cache\Cache"
        Method: "Apc"
      SomeOtherCache:
          Factory: "\Webiny\Component\Cache\Cache"
          Method: "Memcache"
          Arguments: ['127.0.0.1', '11211']
```

See the `ExampleConfig.yaml` for additional details.

Under `Cache` you define the cache drivers by giving each of them a `cache id` and underneath you nest its config. The driver configuration depends on which driver you are using.

If you wish to turn off the cache, use the `BlackHole` driver.

The `Method` parameter must be a valid callback function that will return an instance of `CacheStorage`.

The benefit of defining cache drivers in this way is that the drivers are initialized the second Webiny Framework is loaded. This enables you to access the cache by 'CacheTrait'.

```
    class MyClass
    {
        use \Webiny\Component\Cache\CacheTrait;

        public function myMethod(){
            $this->cache('Frontend')->read('cache_key');
        }
    }
```

Custom `Cache` driver
---------------------

[](#custom-cache-driver)

To implement you own custom cache driver you must first create a class that will implement `\Webiny\Component\Cache\Bridge\CacheInterface`. Once you have that class, create another class with a static function that will return an instance of `CacheDriver`.

```
    class CustomCacheDriver implements \Webiny\Component\Cache\Bridge\CacheInterface
    {
        // implement the interface methods

        // static method that will return the CacheDriver
        function getDriver($cacheId, $param1, $param2, array $options){
            $driver = new static($cacheId, $param1, $param2);

            return \Webiny\Component\Cache\CacheDriver($driver, $options);
        }
    }
```

Now just set your class and the static method as the `Method` inside your config and you can access the cache over the `CacheTrait`.

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

```
$ cd path/to/Webiny/Component/Cache/
$ composer.phar install
$ phpunit

```

Make sure that you also set your cache driver details in `Tests/ExampleConfig.yaml`.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity73

Established project with proven stability

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

Recently: every ~5 days

Total

22

Last Release

3153d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.2.1PHP &gt;=5.5.9

1.5.x-devPHP ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (33 commits)")

---

Tags

rediscacheapcmemcachecouchbase

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/webiny-cache/health.svg)](https://phpackages.com/packages/webiny-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)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.1k](/packages/ihor-cachalot)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[robinn/phpcacheadmin

A web dashboard for your favorite caching system.

4441.1k1](/packages/robinn-phpcacheadmin)

PHPackages © 2026

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