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


PHP StorageInterface::getItems方法代码示例

本文整理汇总了PHP中Zend\Cache\Storage\StorageInterface::getItems方法的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface::getItems方法的具体用法?PHP StorageInterface::getItems怎么用?PHP StorageInterface::getItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Cache\Storage\StorageInterface的用法示例。


在下文中一共展示了StorageInterface::getItems方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetAndGetExpiredItems

 public function testSetAndGetExpiredItems()
 {
     $capabilities = $this->_storage->getCapabilities();
     if ($capabilities->getMinTtl() === 0) {
         $this->markTestSkipped("Adapter doesn't support item expiration");
     }
     $ttl = $capabilities->getTtlPrecision();
     $this->_options->setTtl($ttl);
     $items = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3');
     $this->assertSame(array(), $this->_storage->setItems($items));
     // wait until expired
     $wait = $ttl + $capabilities->getTtlPrecision();
     usleep($wait * 2000000);
     $rs = $this->_storage->getItems(array_keys($items));
     if (!$capabilities->getUseRequestTime()) {
         $this->assertEquals(array(), $rs);
     } else {
         ksort($rs);
         $this->assertEquals($items, $rs);
     }
     $this->_options->setTtl(0);
     if ($capabilities->getExpiredRead()) {
         $rs = $this->_storage->getItems(array_keys($items));
         ksort($rs);
         $this->assertEquals($items, $rs);
     }
 }
开发者ID:ninahuanca,项目名称:zf2,代码行数:27,代码来源:CommonAdapterTest.php

示例2: delegatesGetItems

 /**
  * @test
  */
 public function delegatesGetItems()
 {
     $items = ['foo'];
     $cached = ['foo' => 'bar'];
     $this->storage->getItems($items)->willReturn($cached);
     $return = $this->cache->getItems($items);
     $this->assertSame($cached, $return);
 }
开发者ID:koinephp,项目名称:DelayedCache,代码行数:11,代码来源:DelayedCacheTest.php

示例3: getItems

 /**
  * Returns a traversable set of cache items.
  *
  * @param array $keys
  * An indexed array of keys of items to retrieve.
  *
  * @throws InvalidArgumentException
  *   If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
  *   MUST be thrown.
  *
  * @return array|\Traversable
  *   A traversable collection of Cache Items keyed by the cache keys of
  *   each item. A Cache item will be returned for each key, even if that
  *   key is not found. However, if no keys are specified then an empty
  *   traversable MUST be returned instead.
  */
 public function getItems(array $keys = [])
 {
     $this->validateKeys($keys);
     try {
         $cacheItems = $this->storage->getItems($keys);
     } catch (Exception\InvalidArgumentException $e) {
         throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
     } catch (Exception\ExceptionInterface $e) {
         throw new CacheException($e->getMessage(), $e->getCode(), $e);
     }
     $items = [];
     foreach ($cacheItems as $key => $value) {
         $items[$key] = new CacheItem($key, $value, true);
     }
     // Return empty items for any keys that where not found
     foreach (array_diff($keys, array_keys($cacheItems)) as $key) {
         $items[$key] = new CacheItem($key, null, false);
     }
     return $items;
 }
开发者ID:Nyholm,项目名称:zend-cache-psr6,代码行数:36,代码来源:CacheItemPoolAdapter.php

示例4: testSetAndGetExpiredItems

 public function testSetAndGetExpiredItems()
 {
     $capabilities = $this->_storage->getCapabilities();
     if ($capabilities->getMinTtl() === 0) {
         $this->markTestSkipped("Adapter doesn't support item expiration");
     }
     // item definition
     $itemsHigh = ['keyHigh1' => 'valueHigh1', 'keyHigh2' => 'valueHigh2', 'keyHigh3' => 'valueHigh3'];
     $itemsLow = ['keyLow1' => 'valueLow1', 'keyLow2' => 'valueLow2', 'keyLow3' => 'valueLow3'];
     $items = $itemsHigh + $itemsLow;
     // set items with high TTL
     $this->_options->setTtl(123456);
     $this->assertSame([], $this->_storage->setItems($itemsHigh));
     // set items with low TTL
     $ttl = $capabilities->getTtlPrecision();
     $this->_options->setTtl($ttl);
     $this->waitForFullSecond();
     $this->assertSame([], $this->_storage->setItems($itemsLow));
     // wait until expired
     $wait = $ttl + $capabilities->getTtlPrecision();
     usleep($wait * 2000000);
     $rs = $this->_storage->getItems(array_keys($items));
     ksort($rs);
     // make comparable
     if ($capabilities->getExpiredRead()) {
         // if item expiration will be done on read there is no difference
         // between the previos set items in TTL.
         // -> all items will be expired
         $this->assertEquals([], $rs);
         // after disabling TTL all items will be available
         $this->_options->setTtl(0);
         $rs = $this->_storage->getItems(array_keys($items));
         ksort($rs);
         // make comparable
         $this->assertEquals($items, $rs);
     } elseif ($capabilities->getUseRequestTime()) {
         // if the request time will be used as current time all items will
         // be available as expiration doesn't work within the same process
         $this->assertEquals($items, $rs);
     } else {
         $this->assertEquals($itemsHigh, $rs);
     }
 }
开发者ID:MehrAlsNix,项目名称:zf-couchbase2,代码行数:43,代码来源:CommonAdapterTest.php

示例5: testSetGetHasAndRemoveItemsWithNamespace

 public function testSetGetHasAndRemoveItemsWithNamespace()
 {
     $items = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3');
     $this->_options->setNamespace('defaultns1');
     $this->assertSame(array(), $this->_storage->setItems($items));
     $this->_options->setNamespace('defaultns2');
     $this->assertSame(array(), $this->_storage->hasItems(array_keys($items)));
     $this->_options->setNamespace('defaultns1');
     $rs = $this->_storage->getItems(array_keys($items));
     $this->assertInternalType('array', $rs);
     foreach ($items as $key => $value) {
         $this->assertArrayHasKey($key, $rs);
         $this->assertEquals($value, $rs[$key]);
     }
     $rs = $this->_storage->hasItems(array_keys($items));
     $this->assertInternalType('array', $rs);
     $this->assertEquals(count($items), count($rs));
     foreach ($items as $key => $value) {
         $this->assertContains($key, $rs);
     }
     // remove the first and the last item
     $this->assertSame(array('missing'), $this->_storage->removeItems(array('missing', 'key1', 'key3')));
     unset($items['key1'], $items['key3']);
     $rs = $this->_storage->getItems(array_keys($items));
     $this->assertInternalType('array', $rs);
     foreach ($items as $key => $value) {
         $this->assertArrayHasKey($key, $rs);
         $this->assertEquals($value, $rs[$key]);
     }
     $rs = $this->_storage->hasItems(array_keys($items));
     $this->assertInternalType('array', $rs);
     $this->assertEquals(count($items), count($rs));
     foreach ($items as $key => $value) {
         $this->assertContains($key, $rs);
     }
 }
开发者ID:antoinealej,项目名称:HomeStuff,代码行数:36,代码来源:DoctrineCacheStorageTest.php

示例6: getItems

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


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