/** * Tests the Joomla\Cache\Item class. * * @return void * * @since 1.0 */ public function testItem() { $this->assertEquals('foo', $this->instance->getKey()); $this->assertNull($this->instance->getValue()); $this->assertFalse($this->instance->isHit()); $this->instance->setValue('bar'); $this->assertEquals('bar', $this->instance->getValue()); $this->assertTrue($this->instance->isHit()); }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 1.0 */ public function get($key) { $item = new Item($key); if ($this->exists($key)) { $item->setValue(xcache_get($key)); } return $item; }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 1.0 */ public function get($key) { $item = new Item($key); if (isset(self::$store[$key])) { $item->setValue(self::$store[$key]); } return $item; }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 1.0 */ public function get($key) { $item = new Item($key); $success = true; $value = wincache_ucache_get($key, $success); if ($success) { $item->setValue($value); } return $item; }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 1.0 */ public function get($key) { $this->connect(); $value = $this->driver->get($key); $item = new Item($key); if ($value !== false) { $item->setValue($value); } return $item; }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 1.0 * @throws \RuntimeException */ public function get($key) { $success = false; $value = apc_fetch($key, $success); $item = new Item($key); if ($success) { $item->setValue($value); } return $item; }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 1.0 */ public function getItem($key) { $item = new Item($key); try { $value = $this->getValue($key); $item->setValue($value); } catch (\Exception $e) { /** * Backend caching mechanisms may throw exceptions * to indicate missing data. Catch all exceptions * so program flow is uninterrupted. For misses * we can safely do nothing and return the * CacheItem we created since it flags itself as * a miss when constructed. Specific cache classes * should override this method and deal with * exceptions appropriately. */ } return $item; }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 1.0 * @throws \RuntimeException */ public function get($key) { // If the cached data has expired remove it and return. if ($this->exists($key) && $this->isExpired($key)) { try { $this->remove($key); } catch (\RuntimeException $e) { throw new \RuntimeException(sprintf('Unable to clean expired cache entry for %s.', $key), null, $e); } return new Item($key); } if (!$this->exists($key)) { return new Item($key); } $resource = @fopen($this->fetchStreamUri($key), 'rb'); if (!$resource) { throw new \RuntimeException(sprintf('Unable to fetch cache entry for %s. Connot open the resource.', $key)); } // If locking is enabled get a shared lock for reading on the resource. if ($this->options['file.locking'] && !flock($resource, LOCK_SH)) { throw new \RuntimeException(sprintf('Unable to fetch cache entry for %s. Connot obtain a lock.', $key)); } $data = stream_get_contents($resource); // If locking is enabled release the lock on the resource. if ($this->options['file.locking'] && !flock($resource, LOCK_UN)) { throw new \RuntimeException(sprintf('Unable to fetch cache entry for %s. Connot release the lock.', $key)); } fclose($resource); $item = new Item($key); $item->setValue(unserialize($data)); return $item; }