本文整理汇总了PHP中Zend\Cache\Storage\StorageInterface::setOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface::setOptions方法的具体用法?PHP StorageInterface::setOptions怎么用?PHP StorageInterface::setOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Cache\Storage\StorageInterface
的用法示例。
在下文中一共展示了StorageInterface::setOptions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delegatesSetOptions
/**
* @test
*/
public function delegatesSetOptions()
{
$options = ['foo'];
$return = $this->cache->setOptions($options);
$this->assertSame($this->cache, $return);
$this->storage->setOptions($options)->shouldHaveBeenCalled();
}
示例2: save
/**
* Persists a cache item immediately.
*
* @param CacheItemInterface $item
* The cache item to save.
*
* @return bool
* True if the item was successfully persisted. False if there was an error.
*/
public function save(CacheItemInterface $item)
{
if (!$item instanceof CacheItem) {
throw new InvalidArgumentException('$item must be an instance of ' . CacheItem::class);
}
$this->validateKey($item->getKey());
try {
$options = false;
$expiration = $item->getExpiration();
// @todo I can't see any way to set the TTL on an individual item except by temporarily overwriting the
// option on the storage adapter. Not sure if all storage adapters will support this...
if ($expiration instanceof DateTime) {
$options = $this->storage->getOptions();
$new = clone $options;
$interval = $expiration->diff(new DateTime(), true);
$new->setTtl($interval->format('%s'));
$this->storage->setOptions($new);
}
$saved = $this->storage->setItem($item->getKey(), $item->get());
if ($options) {
$this->storage->setOptions($options);
}
} catch (Exception\InvalidArgumentException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
} catch (Exception\ExceptionInterface $e) {
throw new CacheException($e->getMessage(), $e->getCode(), $e);
}
return $saved;
}
示例3: getItem
/**
* @param $cacheKey
* @param Closure $closure
* @param null $lifetime
* @return mixed
*/
public function getItem($cacheKey, Closure $closure, $lifetime = null)
{
// we have to check if we enable the caching in config
if (!$this->isCachingEnable()) {
return $closure();
}
$data = $this->cachingService->getItem($cacheKey);
if (!$data) {
$data = $closure();
if ($lifetime > 0) {
$this->cachingService->setOptions($this->cachingService->getOptions()->setTtl($lifetime));
}
$this->cachingService->setItem($cacheKey, $data);
}
return $data;
}
示例4: testOptionsFluentInterface
public function testOptionsFluentInterface()
{
$options = $this->_storage->getOptions();
foreach ($options->toArray() as $option => $value) {
$method = ucwords(str_replace('_', ' ', $option));
$method = 'set' . str_replace(' ', '', $method);
$this->assertSame($options, $options->{$method}($value), "Method '{$method}' doesn't implement the fluent interface");
}
$this->assertSame($this->_storage, $this->_storage->setOptions($options), "Method 'setOptions' doesn't implement the fluent interface");
}
示例5: setOptions
public function setOptions($options)
{
$this->storage->setOptions($options);
return $this;
}