/** * {@inheritDoc} */ protected function doGetStats() { /* @var $storage TotalSpaceCapableInterface */ /* @var $storage AvailableSpaceCapableInterface */ $storage = $this->storage; return array(Cache::STATS_HITS => $this->storage->getMetadata(Cache::STATS_HITS), Cache::STATS_MISSES => $this->storage->getMetadata(Cache::STATS_MISSES), Cache::STATS_UPTIME => $this->storage->getMetadata(Cache::STATS_UPTIME), Cache::STATS_MEMORY_USAGE => $storage instanceof TotalSpaceCapableInterface ? $storage->getTotalSpace() : null, Cache::STATS_MEMORY_AVAILIABLE => $storage instanceof AvailableSpaceCapableInterface ? $storage->getAvailableSpace() : null); }
/** * * @param string $filename * @param \Soluble\Media\BoxDimension $box * @param string $format * @param int $quality * @throws \Soluble\Media\Converter\Exception * @throws \Exception */ public function getThumbnail($filename, BoxDimension $box, $format = null, $quality = null) { $width = $box->getWidth(); $height = $box->getHeight(); if ($quality === null) { $quality = $this->default_quality; } $cache_key = md5("{$filename}/{$width}/{$height}/{$quality}/{$format}"); if ($this->cacheEnabled && $this->cacheStorage->hasItem($cache_key)) { $cacheMd = $this->cacheStorage->getMetadata($cache_key); if ($cacheMd['mtime'] < filemtime($filename)) { // invalid cache $binaryContent = $this->generateThumbnail($filename, $box, $format, $quality); $this->cacheStorage->setItem($cache_key, $binaryContent); } else { $binaryContent = $this->cacheStorage->getItem($cache_key); } } else { $binaryContent = $this->generateThumbnail($filename, $box, $format, $quality); $this->cacheStorage->setItem($cache_key, $binaryContent); } switch ($format) { case 'jpg': $content_type = 'image/jpeg'; break; case 'png': $content_type = 'image/png'; break; case 'gif': $content_type = 'image/gif'; break; default: throw new \Exception("Unsupported format '{$format}'"); } header("Content-type: {$content_type}", true); header("Accept-Ranges: bytes", true); header("Cache-control: max-age=2592000, public", true); header("Content-Disposition: inline; filename=\"{$filename}\";", true); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT', true); header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('+1 years')) . ' GMT', true); //header('Content-Disposition: attachment; filename="downloaded.pdf"'); header('Pragma: cache', true); echo $binaryContent; die; }
/** * Get current key, value or metadata. * * @return mixed */ public function current() { if ($this->mode == IteratorInterface::CURRENT_AS_SELF) { return $this; } $key = $this->key(); if ($this->mode == IteratorInterface::CURRENT_AS_METADATA) { return $this->storage->getMetadata($key); } elseif ($this->mode == IteratorInterface::CURRENT_AS_VALUE) { return $this->storage->getItem($key); } return $key; }
/** * Load an entry belonging to the given key from our cache (if any) * * @param string $key key to look for in the cache (should match /^[a-z0-9_+-]*$/Di) * @param int $mtime unix timestamp to compare the cache entry with (the entry will be ignored if older than $mtime) * @return mixed entry from cache or false if its key isn't found in cache or the entry is too old */ protected static function loadFromCache($key, $mtime = 0) { try { self::validateCache(); } catch (\Exception $exception) { // Fake an exception from getItem, so the cache's own EventManager can determine what to do with it $result = false; return self::triggerCacheException('getItem', array('key' => &$key), $result, $exception); } if (!self::$cache->hasItem($key)) { return false; } $meta = self::$cache->getMetadata($key); if (!array_key_exists('mtime', $meta) || $meta['mtime'] < $mtime) { return false; } return self::$cache->getItem($key); }
public function testGetMetadataReturnsFalseIfNonReadable() { $this->_options->setReadable(false); $this->assertTrue($this->_storage->setItem('key', 'value')); $this->assertFalse($this->_storage->getMetadata('key')); }
/** * @test */ public function delegatesGetMetadata() { $this->storage->getMetadata('cacheKey')->willReturn(true); $return = $this->cache->getMetadata('cacheKey'); $this->assertTrue($return); }
public function getMetadata($key) { return $this->storage->getMetadata($key); }