/** * @dataProvider dataProviderItens */ public function testGravaItem($key, $value) { $pool = new CacheItemPool('Apc'); $item = new CacheItem($key); $item->set($value, 60); $this->assertTrue($pool->save($item)); $restored = $pool->getItem($key); $this->assertEquals($value, $restored->get()); }
/** * @param string $key * * @return CacheItem|\Psr\Cache\CacheItemInterface */ public function getItem($key) { $item = new CacheItem($key); $cached = $this->getDriver()->get($key); if ($cached) { $item->set($cached); $item->setHits(1); } return $item; }
/** * Stores routes in cache. * * @param array $routes Routes to store * * @author Benjamin Carl <*****@*****.**> */ protected function store(array $routes = []) { // Get cache instance - at this point all PSR-6 compatibles are allowed $cache = $this->getRegistry()->getCache(); // Check if we use scopes ... if ($cache instanceof Doozr_Cache_Service) { $cache->create($this->getUuid(), $routes, null, $this->getScope()); } else { $item = new CacheItem($this->getUuid()); $item->set($routes); $cache->save($item); } }
/** * Returns a collection of userland configuration files (including path). * * @author Benjamin Carl <*****@*****.**> * * @return array Collection of userland configuration files * @static */ protected static function retrieveUserlandConfigurationFiles() { $appEnvironment = self::$registry->getParameter('doozr.app.environment'); $caching = self::$registry->getParameter('doozr.kernel.caching'); $exists = null; $stale = false; $file = self::$registry->getPath()->get('app', 'Data\\Private\\Config\\.configuration.' . $appEnvironment . '.json'); // Try to load information from cache! if (true === $caching) { try { $exists = self::$registry->getCache()->getItem($file)->get(); } catch (Doozr_Cache_Service_Exception $exception) { // Intentionally left empty } } if (null === $exists) { $stale = true; $exists = true === self::$registry->getFilesystem()->exists($file) && true === self::$registry->getFilesystem()->readable($file); } // Cache items found for reuse later if (true === $stale && true === $caching) { $cacheItem = new CacheItem($file); $cacheItem->set($exists); self::$registry->getCache()->save($cacheItem); } // Return collection of service configuration files return true === $exists ? [$file] : []; }
/** * Returns a Cache Item representing the specified key. * * This method must always return an ItemInterface object, even in case of a cache miss. It MUST NOT return null. * * @param string $key The key for which to return the corresponding Cache Item. * * @throws InvalidArgumentException If the $key string is not a legal value an exception MUST be thrown. * * @author Benjamin Carl <*****@*****.**> * * @return CacheItemInterface The corresponding Cache Item. */ public function getItem($key) { // Return an item in all cases $item = new CacheItem($key); try { $data = $this->read($key, null, true); $item->set($data[2], $data[0] - time()); } catch (Doozr_Cache_Service_Exception $exception) { } return $item; }