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

ActiveLibrary[Caching](/categories/caching)

phossa/phossa-cache
===================

The PSR-6 compliant PHP caching library.

1.0.10(10y ago)245MITPHPPHP &gt;=5.4.0

Since Jan 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phossa/phossa-cache)[ Packagist](https://packagist.org/packages/phossa/phossa-cache)[ Docs](https://github.com/phossa/phossa-cache)[ RSS](/packages/phossa-phossa-cache/feed)WikiDiscussions master Synced 4w ago

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

phossa-cache \[ABANDONED\]
==========================

[](#phossa-cache-abandoned)

[![Build Status](https://camo.githubusercontent.com/143371842bf4bd8ee59f33c9b42283f3cc3c59a5ade63ab040262916d3cd2a03/68747470733a2f2f7472617669732d63692e6f72672f70686f7373612f70686f7373612d63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa/phossa-cache)[![HHVM](https://camo.githubusercontent.com/a8014ef981482f02f83e04e0e20c52a3644924702fe821405d83ba29bb556c39/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f70686f7373612f70686f7373612d63616368652e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/phossa/phossa-cache)[![Latest Stable Version](https://camo.githubusercontent.com/9b2c5eeb62bbcc52b53be3526cc694aa076fd273ad61300eaf9d0ac98bb83f00/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f7373612f70686f7373612d63616368652e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa/phossa-cache)[![License](https://camo.githubusercontent.com/b9c44ca878e36044e110ba78a1840fd00980f47c7f0c69102874c50829bf0136/68747470733a2f2f706f7365722e707567782e6f72672f70686f7373612f70686f7373612d63616368652f6c6963656e7365)](http://mit-license.org/)

**See new lib at [phoole/cache](https://github.com/phoole/cache)**Introduction
------------------------------------------------------------------------------

[](#see-new-lib-at-phoolecacheintroduction)

Phossa-cache is a PSR-6 compliant caching library. It supports various drivers and useful features like bypass, encrypt, stampede protection, garbage collect, taggable item etc.

More information about [PSR-6](http://www.php-fig.org/psr/psr-6/) and [PSR-6 Meta](http://www.php-fig.org/psr/psr-6/meta/)

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

[](#installation)

Install via the `composer` utility.

```
composer require "phossa/phossa-cache=1.*"

```

or add the following lines to your `composer.json`

```
{
    "require": {
       "phossa/phossa-cache": "^1.0.8"
    }
}
```

Features
--------

[](#features)

- Fully PSR-6 compliant. Maybe the most feature-rich PSR-6 caching package you will find at github at this time.
- Support all serializable PHP datatypes.
- **Extensions**:

    - **Bypass**: If sees a trigger in URL (e.g. '?nocache=true'), bypass the cache.
    - **Stampede**: Whenever cached object's lifetime is less than a configurable time, by certain percentage, the cache will return false on 'isHit()' which will trigger re-generation of the object.
    - **Encrypt**: A simple extension to encrypt the serialized content
    - **GarbageCollect**: A simple extension to auto-clean the cache pool.
    - **Taggable**: Item is taggable and can be cleared by tag.
    - **DistributeMiss**: Even out the spikes of item misses by alter expiration time a little bit.
- **Drivers**

    - **FilesystemDriver**

        The filesystem driver stores cached item in filesystem. It stores cached items in a md5-filename flat file. Configurable settings are

        - `dir_root`: the base directory for the filesystem cache
        - `hash_level`: hashed subdirectory level. default to 2
        - `file_pref`: cached item filename prefix
        - `file_suff`: cached item filename suffix

        ```
        /*
         * construct the driver manually
         */
        $driver = new Driver\FilesystemDriver([
            'hash_level'    => 1,
            'file_pref'     => 'cache.',
            'dir_root'      => '/var/tmp/cache',
        ]);
        ```
    - **NullDriver**

        The blackhole driver. used as fallback driver for all other drivers.
    - **Fallback driver**

        User may configure a fallback driver if the desired driver is not ready. The `NullDriver` is the final fallback for all other drivers.

        ```
        // default memcache driver
        $driver = new Driver\MemcacheDriver([
            'server' => [ '127.0.0.1', 11211 ]
        ]);

        // set a fallback filesystem driver
        $driver->setFallback(new Driver\FilesystemDriver([
            'dir_root' => '/var/tmp/cache'
        ]));

        $cache = new CachePool($driver);
        ```
    - **CompositeDriver**

        The `CompositeDriver` consists of two drivers, the front-end driver and the backend driver. User filters cachable objects by defining a `tester`callable which will determine which objects stores to both ends or backend only.

        ```
        /*
         * set the composite driver
         */
        $driver = new Driver\CompositeDriver(
            // front-end driver
            new Driver\MemcacheDriver([
                'server' => [ '127.0.0.1', 11211 ]
            ]),

            // backend driver
            new Driver\FilesystemDriver([
                'dir_root' => '/var/tmp/cache'
            ]),

            // other settings
            [
                // if size > 10k, stores at backend only
                'tester' => function($item) {
                    if (strlen($item->get()) > 10240) return false;
                    return true;
                }
            ]
        );
        ```
- **Logging**

    The phossa-cache supports psr-3 compliant logger. Also provides a `log()`method for logging.

    ```
    /*
     * set the logger
     */
    $cache->setLogger($psrLogger);
    $cache->log('info', 'this is an info');
    ```

    Or configure with logger at cache init

    ```
    /*
     * the third argument is used for configuring CachePool
     */
    $cache = new CachePool($driver, [],
        'logger' => $psrLogger
    );
    $cache->log('info', 'this is an info');
    ```
- **Error**

    No exceptions thrown during caching process. So only errors will be used.

    ```
    /*
     * create cache pool, exceptions may thrown here
     */
    $cache = new CachePool();
    $cache->setLogger($psrLogger);

    $item = $cache->getItem('widget_list');
    $val  = $item->get();
    if ($cache->hasError()) {
        $cache->log('error', $cache->getError());
        $widget_list = compute_expensive_widget_list();
        $item->set($widget_list);
        $item->expiresAfter(3600); // expires after an hour
        $cache->save($item);
        if ($cache->hasError()) $cache->log('error', $cache->getError());
    } else {
        $widget_list = $val;
    }
    ```
- I18n

    Messages are in `Message\Message.php`. I18n is possible. See phossa-shared package for detail.
- Support PHP 5.4+, PHP 7.0, HHVM.
- PHP7 ready for return type declarations and argument type declarations.
- PSR-1, PSR-2, PSR-3, PSR-4, PSR-6 compliant.

Usage
-----

[](#usage)

- The simple usage

    ```
    /*
     * use the default FilesystemDriver which also set default cache
     * directory to sys_get_temp_dir() .'/cache'
     */
    $cache = new CachePool();

    $item = $cache->getItem('widget_list');
    if (!$item->isHit()) {
        $value = compute_expensive_widget_list();
        $item->set($value);
        $cache->save($item);
    }
    $widget_list = $item->get();
    ```
- Configure the driver

    ```
    $driver = new Driver\FilesystemDriver([
        'hash_level'    => 1, // subdirectory hash levels
        'file_pref'     => 'cache.', // cache file prefix
        'file_suff'     => '.txt',   // cache file suffix
        'dir_root'      => '/var/tmp/cache' // reset cache root
    ]);

    $cache = new CachePool($driver);
    ```
- Use extensions

    ```
    /*
     * SerializeExtension is the default ext, always used.
     * Second argument is an array of ExtensionInterface or config array
     */
    $cache = new CachePool(
        $driver,
        [
            new Extension\BypassExtension(),
            new Extension\StampedeExtension(['probability' => 80 ])
        ]
    );
    ```

    or `addExtension()`

    ```
    $cache = new CachePool($driver);
    $cache->addExtension(new Extension\BypassExtension());
    ```
- Hierarchal cache support

    Directory-style hierarchal structure is supported in `FilesystemDriver` and so other coming drivers.

    ```
    // hierarchy key
    $item = $cache->getItem('mydomain/host1/newfile_xxx');

    // ending '/' means delete the hierarchy structure
    $cache->deleteItem('mydomain/host1/');
    ```

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa/phossa-shared 1.0.6
- psr/cache 1.\*

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Recently: every ~22 days

Total

8

Last Release

3727d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8499165?v=4)[Hong Zhang](/maintainers/phossa)[@phossa](https://github.com/phossa)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (39 commits)")

---

Tags

cachecachingpsr-6phossa

### Embed Badge

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

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

###  Alternatives

[symfony/cache

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

4.2k373.5M3.2k](/packages/symfony-cache)[tedivm/stash

The place to keep your cache.

9614.9M127](/packages/tedivm-stash)[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1077.3M152](/packages/laminas-laminas-cache)[cache/adapter-common

Common classes for PSR-6 adapters

11125.4M38](/packages/cache-adapter-common)[beste/in-memory-cache

A PSR-6 In-Memory cache that can be used as a fallback implementation and/or in tests.

2515.9M12](/packages/beste-in-memory-cache)[cache/hierarchical-cache

A helper trait and interface to your PSR-6 cache to support hierarchical keys.

6016.6M11](/packages/cache-hierarchical-cache)

PHPackages © 2026

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