for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Digia\GraphQL\Cache;
use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\InvalidArgumentException;
trait CacheAwareTrait
{
/**
* @var CacheInterface
*/
protected $cache;
* @return string
abstract protected function getCachePrefix(): string;
* @param mixed $key
* @param mixed|null $default
* @return mixed
* @throws InvalidArgumentException
public function getFromCache($key, $default = null)
return $this->cache->get($key, $default);
}
* @return bool
public function isInCache($key): bool
return $this->cache->has($key);
public function deleteFromCache($key): bool
return $this->cache->delete($key);
* @param mixed $value
* @param null $ttl
$ttl
null
public function setInCache($key, $value, $ttl = null): bool
return $this->cache->set($key, $value, $ttl);
*
public function clearCache()
$this->cache->clear();
protected function getCacheKey($key): string
return $this->getCachePrefix() . $key;