for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Ds\Cache;
/**
* Class Cache
* @package Ds\Cache
*/
class Cache implements CacheInterface
{
* @var CacheStorageInterface
protected $cache;
* Create new instance with $CacheStorage
*
* @param CacheStorageInterface $cacheStorage
* @return CacheInterface
public function withCacheStorage(CacheStorageInterface $cacheStorage)
$new = clone $this;
$new->cache = $cacheStorage;
return $new;
}
* Get Cache Storage
* @return CacheStorageInterface
public function getCacheStorage()
return $this->cache;
* Cache constructor.
* @param CacheStorageInterface|null $cacheStorage
public function __construct(CacheStorageInterface $cacheStorage = null)
$this->cache = $cacheStorage;
if ($cacheStorage === null) {
$this->cache = new NullStorage();
* Check if cache key exists.
* @param $key
* @return bool
public function has($key)
return $this->cache->has($key);
* Save Cache Value.
* @param string $key
* @param mixed $value
* @param int $expires
* @return void
public function set($key, $value, $expires)
return $this->cache->set($key, $value, $expires);
* Get Cache Value from key.
* @return mixed
public function get($key = '')
return $this->cache->get($key);
* Delete Cache Key.
public function delete($key)
$this->cache->delete($key);