for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Marek\OpenWeatherMap\Core\Cache;
use Marek\OpenWeatherMap\API\Cache\HandlerInterface;
use Marek\OpenWeatherMap\API\Exception\ItemNotFoundException;
use Symfony\Component\Cache\Adapter\AdapterInterface;
class SymfonyCache implements HandlerInterface
{
/**
* @var \Symfony\Component\Cache\Adapter\AdapterInterface
*/
protected $cache;
* @var int
protected $timeToLive;
public function __construct(AdapterInterface $cache, int $timeToLive = 3600)
$this->cache = $cache;
$this->timeToLive = $timeToLive;
}
public function has(string $cacheKey): bool
$key = $this->computeKey($cacheKey);
$item = $this->cache->getItem($key);
return $item->isHit();
public function get(string $cacheKey): array
return $item->get();
public function set(string $cacheKey, array $data): void
$item->expiresAfter($this->timeToLive);
$item->set($data);
$this->cache->save($item);
protected function computeKey(string $cacheKey): string
return md5(self::CACHE_KEY_PREFIX . $cacheKey);