當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。