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

ActiveLibrary[Caching](/categories/caching)

nilportugues/repository-cache
=============================

Implementation of a base repository with cache layer using StashPHP

3.0.2(9y ago)7236[1 issues](https://github.com/PHPRepository/php-repository-cache/issues)MITPHPPHP &gt;=7.0.0

Since Jan 26Pushed 9y agoCompare

[ Source](https://github.com/PHPRepository/php-repository-cache)[ Packagist](https://packagist.org/packages/nilportugues/repository-cache)[ Docs](http://nilportugues.com)[ RSS](/packages/nilportugues-repository-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (4)Versions (9)Used By (0)

Repository Cache
================

[](#repository-cache)

[![PHP7 Tested](https://camo.githubusercontent.com/e16072d3e30c6b30d6c005e75ea14d1ee1ea1fd8f31184fc4dad2e23980c1bc2/687474703a2f2f7068702d6579652e636f6d2f62616467652f6e696c706f727475677565732f7265706f7369746f72792d63616368652f70687037302e737667)](https://camo.githubusercontent.com/e16072d3e30c6b30d6c005e75ea14d1ee1ea1fd8f31184fc4dad2e23980c1bc2/687474703a2f2f7068702d6579652e636f6d2f62616467652f6e696c706f727475677565732f7265706f7369746f72792d63616368652f70687037302e737667)[![Build Status](https://camo.githubusercontent.com/c1ac7e0bbf12a6e9be41bd1e8849d2823c0541faae1356360a56cde56375759a/68747470733a2f2f7472617669732d63692e6f72672f5048505265706f7369746f72792f7265706f7369746f72792d63616368652e737667)](https://travis-ci.org/PHPRepository/repository-cache) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/618e3a990fa0b42cf9f631564abde19b21063035b80c3f5b17303d898c09a5fa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e696c706f727475677565732f7068702d7265706f7369746f72792d63616368652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nilportugues/php-repository-cache/?branch=master) [![SensioLabsInsight](https://camo.githubusercontent.com/67b5c023de82d066e110a483622a8ad2f5af9b437c21d25c6cdfccaf147441c8/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f32393431333634662d633734342d343638302d616335332d6137376635333238613436642f6d696e692e706e67)](https://insight.sensiolabs.com/projects/2941364f-c744-4680-ac53-a77f5328a46d) [![Latest Stable Version](https://camo.githubusercontent.com/6b4556d92f8c6497058efafdb2c2bde945ce80bd49f940de503129006ded4861/68747470733a2f2f706f7365722e707567782e6f72672f6e696c706f727475677565732f7265706f7369746f72792d63616368652f762f737461626c65)](https://packagist.org/packages/nilportugues/repository-cache) [![Total Downloads](https://camo.githubusercontent.com/b97d589cf3aa845b0d035b41d5c6f268f0fa70b3586dd6db8a8b9c29b208e0ab/68747470733a2f2f706f7365722e707567782e6f72672f6e696c706f727475677565732f7265706f7369746f72792d63616368652f646f776e6c6f616473)](https://packagist.org/packages/nilportugues/repository-cache) [![License](https://camo.githubusercontent.com/dae378b31b7d3f7593991fcc0fbf219a9d6f8eca42640127bf757363a3ffe179/68747470733a2f2f706f7365722e707567782e6f72672f6e696c706f727475677565732f7265706f7369746f72792d63616368652f6c6963656e7365)](https://packagist.org/packages/nilportugues/repository-cache)[![Donate](https://camo.githubusercontent.com/7b6de155df30b37b25eb5fec52f9213680c3dbf067dfb7d7e2850ac4096c7d05/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f534d2e676966)](https://paypal.me/nilportugues)

Repository to be used with *[nilportugues/repository](https://github.com/nilportugues/php-repository)* implementing a PSR-6 cache layer using [StashPHP](http://www.stashphp.com/).

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

[](#installation)

Use [Composer](https://getcomposer.org) to install the package:

```
$ composer require nilportugues/repository-cache
```

Cache Drivers
-------------

[](#cache-drivers)

Repository Cache supports all of Stash's drivers:

- **System**
    - FileSystem
    - Sqlite (requires php-pdo-sqlite extension)
    - APC (requires php-apcu extension)
- **Server**
    - Memcached (requires php-memcache or php-memcached extensions)
    - Redis (requires php-redis extension)
- **Specialized**
    - Ephemeral (in memory cache)
    - Composite

For more information please check out [Stash's documentation](http://www.stashphp.com/Drivers.html).

Usage
-----

[](#usage)

```
use NilPortugues\Foundation\Infrastructure\Model\Repository\Cache\RepositoryCache;
use Stash\Driver\Ephemeral;
use Stash\Driver\Memcache;
use Stash\Pool;

//---------------------------------------------------------------------------
// Definition of cache drivers
//---------------------------------------------------------------------------
$memcached = new Memcache();
$memcached->setOptions(array('servers' => array('127.0.0.1', '11211')));

$cachePool = new Pool();
$cachePool->setDriver(new Ephemeral()); //hit in memory first as always will be faster
$cachePool->setDriver($memcached); //hit memcached second.

$ttl = 3600; //time in second for cache to expire.
$cacheNamespace = Color::class;

//---------------------------------------------------------------------------
// Adding cache to an existing repository
//---------------------------------------------------------------------------
$sqlRepository = new MySQLColorRepository();
$repository = new RepositoryCache($cachePool, $repository, $cacheNamespace, $ttl);

//---------------------------------------------------------------------------
// Now use as normal...
//---------------------------------------------------------------------------
$color = new Color('#@@@@@@', 'New color');
$repository->add($color);
$repository->find(ColorId('#@@@@@@')); //should hit cache and return an instance of Color.
```

Quality
-------

[](#quality)

To run the PHPUnit tests at the command line, go to the tests directory and issue phpunit.

This library attempts to comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/), [PSR-4](http://www.php-fig.org/psr/psr-4/).

If you notice compliance oversights, please send a patch via [Pull Request](https://github.com/nilportugues/php-repository-cache/pulls).

Contribute
----------

[](#contribute)

Contributions to the package are always welcome!

- Report any bugs or issues you find on the [issue tracker](https://github.com/nilportugues/php-repository-cache/issues/new).
- You can grab the source code at the package's [Git repository](https://github.com/nilportugues/php-repository-cache).

Support
-------

[](#support)

Get in touch with me using one of the following means:

- Emailing me at
- Opening an [Issue](https://github.com/nilportugues/php-repository-cache/issues/new)

Authors
-------

[](#authors)

- [Nil Portugués Calderó](http://nilportugues.com)
- [The Community Contributors](https://github.com/nilportugues/php-repository-cache/graphs/contributors)

License
-------

[](#license)

The code base is licensed under the [MIT license](LICENSE).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

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

Recently: every ~35 days

Total

8

Last Release

3560d ago

Major Versions

1.0.1 → 2.1.02016-03-18

2.2.1 → 3.0.02016-08-08

### Community

Maintainers

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

---

Top Contributors

[![nilportugues](https://avatars.githubusercontent.com/u/550948?v=4)](https://github.com/nilportugues "nilportugues (31 commits)")

---

Tags

apcucacheclean-architectureclean-codeddddomain-driven-designephemeralfilesystemhexagonal-architectureinmemorymemcachememcachedperformancephpphp7psr-6redisrepositorysqlitestashphppaginationcacherepositorydddadaptershexagonalnil portuguesnilportuguesports and adaptersportspageable

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[nilportugues/repository

Implementation of a base repository

272.9k6](/packages/nilportugues-repository)[nilportugues/sql-repository

SQL Repository implementation

361.9k](/packages/nilportugues-sql-repository)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)

PHPackages © 2026

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