当前位置: 首页>>代码示例>>PHP>>正文


PHP StorageInterface::addItem方法代码示例

本文整理汇总了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));
 }
开发者ID:drcts,项目名称:closure-cache,代码行数:15,代码来源:Operation.php

示例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());
     }
 }
开发者ID:antarus,项目名称:mystra-pve,代码行数:24,代码来源:AbstractClient.php

示例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'));
     }
 }
开发者ID:MehrAlsNix,项目名称:zf-couchbase2,代码行数:19,代码来源:CommonAdapterTest.php

示例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);
             }
         }
     }
 }
开发者ID:sunnyct,项目名称:silexcmf,代码行数:28,代码来源:HttpKernelListener.php

示例5: testAddItemReturnsFalseIfNonWritable

 public function testAddItemReturnsFalseIfNonWritable()
 {
     $this->_options->setWritable(false);
     $this->assertFalse($this->_storage->addItem('key', 'value'));
     $this->assertFalse($this->_storage->hasItem('key'));
 }
开发者ID:ninahuanca,项目名称:zf2,代码行数:6,代码来源:CommonAdapterTest.php

示例6: delegatesAddItem

 /**
  * @test
  */
 public function delegatesAddItem()
 {
     $this->storage->addItem('cacheKey', 'value')->willReturn(true);
     $return = $this->cache->addItem('cacheKey', 'value');
     $this->assertTrue($return);
 }
开发者ID:koinephp,项目名称:DelayedCache,代码行数:9,代码来源:DelayedCacheTest.php

示例7: addItem

 public function addItem($key, $value)
 {
     return $this->storage->addItem($key, $value);
 }
开发者ID:nasimnabavi,项目名称:DelayedCache,代码行数:4,代码来源:DelayedCache.php


注:本文中的Zend\Cache\Storage\StorageInterface::addItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。