Skip to content

nilportugues/repository-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repository Cache

Build Status Scrutinizer Code Quality SensioLabsInsight Latest Stable Version Total Downloads License Donate

Repository to be used with nilportugues/repository implementing a cache layer using StashPHP.

Installation

Use Composer to install the package:

$ composer require nilportugues/repository-cache

Usage

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

$memcached = new Memcache();
$memcached->setOptions(array('servers' => array('127.0.0.1', '11211')));

$cachePool = new Pool();
$cachePool->setDriver(new Ephemeral());
$cachePool->setDriver($memcached);

/**
 * MySQLColorRepository is an implementation of:
 *  - NilPortugues\Foundation\Domain\Model\Repository\Contracts\PageRepository
 *  - NilPortugues\Foundation\Domain\Model\Repository\Contracts\ReadRepository
 *  - NilPortugues\Foundation\Domain\Model\Repository\Contracts\WriteRepository
 */
$repository = new MySQLColorRepository($data);
$cacheRepository = new RepositoryCache($cachePool, $repository, Color::class, '3600');

/**
 * Color Repository is a wrapper class implementing the same interfaces
 * as the previously defined MySQLColorRepository.
 */
$repository = new ColorRepository($cacheRepository);

//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

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, PSR-2, PSR-4.

If you notice compliance oversights, please send a patch via Pull Request.

Contribute

Contributions to the package are always welcome!

Support

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

Authors

License

The code base is licensed under the MIT license.