本文整理汇总了PHP中Zend\Cache\Storage\StorageInterface::addItem方法的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface::addItem方法的具体用法?PHP StorageInterface::addItem怎么用?PHP StorageInterface::addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Cache\Storage\StorageInterface
的用法示例。
在下文中一共展示了StorageInterface::addItem方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: warm
/**
* @param null|array $arguments Must be serializable.
* @return void
*/
public function warm($arguments = null)
{
$callable = $this->callable;
if (is_array($arguments)) {
$value = call_user_func_array($callable, $arguments);
} else {
$value = $callable();
}
$cacheKey = Cache::makeCacheKey($this->name, $arguments);
$this->storage->addItem($cacheKey, serialize($value));
}
示例2: handleSuccessfulResponse
/**
* @param ResponseInterface $response
* @param ItemInterface $key
* @param array|null $data
*
* @throws \RuntimeException
*
* @return array
*/
protected function handleSuccessfulResponse(\Zend\Http\Response $response, $key)
{
switch ((int) $response->getStatusCode()) {
case 200:
$data = json_decode($response->getBody(), true);
$this->addItem($key, $data);
return $data;
case 304:
return $this->cache->addItem($key);
case 404:
return null;
default:
throw new \RuntimeException('No support added for HTTP Status Code ' . $response->getStatusCode());
}
}
示例3: testAddItemSetsTTL
public function testAddItemSetsTTL()
{
$capabilities = $this->_storage->getCapabilities();
if ($capabilities->getMinTtl() === 0) {
$this->markTestSkipped("Adapter doesn't support item expiration");
}
$ttl = $capabilities->getTtlPrecision();
$this->_options->setTtl($ttl);
$this->waitForFullSecond();
$this->assertTrue($this->_storage->addItem('key', 'value'));
// wait until the item expired
$wait = $ttl + $capabilities->getTtlPrecision();
usleep($wait * 2000000);
if (!$capabilities->getUseRequestTime()) {
$this->assertFalse($this->_storage->hasItem('key'));
} else {
$this->assertTrue($this->_storage->hasItem('key'));
}
}
示例4: onKernelResponse
/**
* Triggered after controller and view calls
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST && $request->isMethodSafe()) {
$key = $this->getKeyFromRequest($request);
$response->setLastModified(new \DateTime());
// If no cache request header exists - do nothing
if ($request->isNoCache() || !$response->isSuccessful()) {
return;
//TODO redirects cache
}
// If response does not exists - put it to cache
if (!$this->storage->hasItem($key)) {
$response->setTtl($this->storage->getOptions()->getTtl());
$data = ['content' => $response->getContent(), 'status' => $response->getStatusCode(), 'headers' => $response->headers->all()];
$this->storage->addItem($key, $data);
if ($this->storage instanceof TaggableInterface) {
$this->storage->setTags($key, $tags);
}
}
}
}
示例5: testAddItemReturnsFalseIfNonWritable
public function testAddItemReturnsFalseIfNonWritable()
{
$this->_options->setWritable(false);
$this->assertFalse($this->_storage->addItem('key', 'value'));
$this->assertFalse($this->_storage->hasItem('key'));
}
示例6: delegatesAddItem
/**
* @test
*/
public function delegatesAddItem()
{
$this->storage->addItem('cacheKey', 'value')->willReturn(true);
$return = $this->cache->addItem('cacheKey', 'value');
$this->assertTrue($return);
}
示例7: addItem
public function addItem($key, $value)
{
return $this->storage->addItem($key, $value);
}