for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Nip\Cache\Cacheable;
use League\Container\Exception\NotFoundException;
use Nip\Cache\Stores\Repository;
use Nip\Container\Container;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
/**
* Trait HasCacheStore
* @package Nip\Cache\Cacheable
*/
trait HasCacheStore
{
protected $cacheStore = null;
* @return Repository
protected function cacheStore()
if ($this->cacheStore === null) {
$this->cacheStore = $this->generateCacheStore();
}
return $this->cacheStore;
protected function generateCacheStore()
try {
return $this->generateCacheStoreFromContainer();
} catch (NotFoundException $exception) {
return $this->generateCacheStoreInMemory();
protected function generateCacheStoreInMemory()
$adapter = new ArrayAdapter();
$store = new Repository($adapter);
return $store;
* @throws NotFoundException
protected function generateCacheStoreFromContainer()
if (function_exists('app')) {
return app('cache.store');
return Container::getInstance()->get('cache.store');