/** * @param array|CacheAdapterInterface|CacheStorageInterface $options Array of options for the cache plugin, * cache adapter, or cache storage object. * - CacheStorageInterface storage: Adapter used to cache responses * - RevalidationInterface revalidation: Cache revalidation strategy * - CanCacheInterface can_cache: Object used to determine if a request can be cached * - bool auto_purge Set to true to automatically PURGE resources when non-idempotent * requests are sent to a resource. Defaults to false. * @throws InvalidArgumentException if no cache is provided and Doctrine cache is not installed */ public function __construct($options = null) { if (!is_array($options)) { if ($options instanceof CacheAdapterInterface) { $options = array('storage' => new DefaultCacheStorage($options)); } elseif ($options instanceof CacheStorageInterface) { $options = array('storage' => $options); } elseif ($options) { $options = array('storage' => new DefaultCacheStorage(CacheAdapterFactory::fromCache($options))); } elseif (!class_exists('Doctrine\\Common\\Cache\\ArrayCache')) { // @codeCoverageIgnoreStart throw new InvalidArgumentException('No cache was provided and Doctrine is not installed'); // @codeCoverageIgnoreEnd } } $this->autoPurge = isset($options['auto_purge']) ? $options['auto_purge'] : false; // Add a cache storage if a cache adapter was provided $this->storage = isset($options['storage']) ? $options['storage'] : new DefaultCacheStorage(new DoctrineCacheAdapter(new ArrayCache())); if (!isset($options['can_cache'])) { $this->canCache = new DefaultCanCacheStrategy(); } else { $this->canCache = is_callable($options['can_cache']) ? new CallbackCanCacheStrategy($options['can_cache']) : $options['can_cache']; } // Use the provided revalidation strategy or the default $this->revalidation = isset($options['revalidation']) ? $options['revalidation'] : new DefaultRevalidation($this->storage, $this->canCache); }
/** * @dataProvider cacheProvider */ public function testCreatesNullCacheAdapterByDefault($cache, $type) { $adapter = CacheAdapterFactory::fromCache($cache); $this->assertInstanceOf($type, $adapter); }
/** * @param mixed $cache Cache used to store cache data * @param string $keyPrefix Provide an optional key prefix to prefix on all cache keys * @param int $defaultTtl Default cache TTL */ public function __construct($cache, $keyPrefix = '', $defaultTtl = 3600) { $this->cache = CacheAdapterFactory::fromCache($cache); $this->defaultTtl = $defaultTtl; $this->keyPrefix = $keyPrefix; }
public function testCreatesNullCacheAdapterByDefault() { $adapter = CacheAdapterFactory::factory(array()); $this->assertInstanceOf('Guzzle\\Cache\\NullCacheAdapter', $adapter); }