Example #1
0
 /**
  * @covers BagOStuff::getMulti
  */
 public function testGetMulti()
 {
     $value1 = array('this' => 'is', 'a' => 'test');
     $value2 = array('this' => 'is', 'another' => 'test');
     $key1 = wfMemcKey('test1');
     $key2 = wfMemcKey('test2');
     $this->cache->add($key1, $value1);
     $this->cache->add($key2, $value2);
     $this->assertEquals($this->cache->getMulti(array($key1, $key2)), array($key1 => $value1, $key2 => $value2));
     // cleanup
     $this->cache->delete($key1);
     $this->cache->delete($key2);
 }
 /**
  * @covers BagOStuff::getMulti
  */
 public function testGetMulti()
 {
     $value1 = array('this' => 'is', 'a' => 'test');
     $value2 = array('this' => 'is', 'another' => 'test');
     $value3 = array('testing a key that may be encoded when sent to cache backend');
     $key1 = wfMemcKey('test1');
     $key2 = wfMemcKey('test2');
     $key3 = wfMemcKey('will-%-encode');
     // internally, MemcachedBagOStuffs will encode to will-%25-encode
     $this->cache->add($key1, $value1);
     $this->cache->add($key2, $value2);
     $this->cache->add($key3, $value3);
     $this->assertEquals(array($key1 => $value1, $key2 => $value2, $key3 => $value3), $this->cache->getMulti(array($key1, $key2, $key3)));
     // cleanup
     $this->cache->delete($key1);
     $this->cache->delete($key2);
     $this->cache->delete($key3);
 }
 /**
  * Do a batch lookup from cache for file stats for all paths
  * used in a list of storage paths or FileOp objects.
  * This loads the persistent cache values into the process cache.
  *
  * @param array $items List of storage paths
  */
 protected final function primeFileCache(array $items)
 {
     $ps = Profiler::instance()->scopedProfileIn(__METHOD__ . "-{$this->name}");
     $paths = array();
     // list of storage paths
     $pathNames = array();
     // (cache key => storage path)
     // Get all the paths/containers from the items...
     foreach ($items as $item) {
         if (self::isStoragePath($item)) {
             $paths[] = FileBackend::normalizeStoragePath($item);
         }
     }
     // Get rid of any paths that failed normalization...
     $paths = array_filter($paths, 'strlen');
     // remove nulls
     // Get all the corresponding cache keys for paths...
     foreach ($paths as $path) {
         list(, $rel, ) = $this->resolveStoragePath($path);
         if ($rel !== null) {
             // valid path for this backend
             $pathNames[$this->fileCacheKey($path)] = $path;
         }
     }
     // Get all cache entries for these container cache keys...
     $values = $this->memCache->getMulti(array_keys($pathNames));
     foreach ($values as $cacheKey => $val) {
         $path = $pathNames[$cacheKey];
         if (is_array($val)) {
             $val['latest'] = false;
             // never completely trust cache
             $this->cheapCache->set($path, 'stat', $val);
             if (isset($val['sha1'])) {
                 // some backends store SHA-1 as metadata
                 $this->cheapCache->set($path, 'sha1', array('hash' => $val['sha1'], 'latest' => false));
             }
             if (isset($val['xattr'])) {
                 // some backends store headers/metadata
                 $val['xattr'] = self::normalizeXAttributes($val['xattr']);
                 $this->cheapCache->set($path, 'xattr', array('map' => $val['xattr'], 'latest' => false));
             }
         }
     }
 }
Example #4
0
 /**
  * Do a batch lookup from cache for file stats for all paths
  * used in a list of storage paths or FileOp objects.
  * This loads the persistent cache values into the process cache.
  *
  * @param array $items List of storage paths or FileOps
  * @return void
  */
 protected final function primeFileCache(array $items)
 {
     wfProfileIn(__METHOD__);
     wfProfileIn(__METHOD__ . '-' . $this->name);
     $paths = array();
     // list of storage paths
     $pathNames = array();
     // (cache key => storage path)
     // Get all the paths/containers from the items...
     foreach ($items as $item) {
         if ($item instanceof FileOp) {
             $paths = array_merge($paths, $item->storagePathsRead());
             $paths = array_merge($paths, $item->storagePathsChanged());
         } elseif (self::isStoragePath($item)) {
             $paths[] = FileBackend::normalizeStoragePath($item);
         }
     }
     // Get rid of any paths that failed normalization...
     $paths = array_filter($paths, 'strlen');
     // remove nulls
     // Get all the corresponding cache keys for paths...
     foreach ($paths as $path) {
         list(, $rel, ) = $this->resolveStoragePath($path);
         if ($rel !== null) {
             // valid path for this backend
             $pathNames[$this->fileCacheKey($path)] = $path;
         }
     }
     // Get all cache entries for these container cache keys...
     $values = $this->memCache->getMulti(array_keys($pathNames));
     foreach ($values as $cacheKey => $val) {
         if (is_array($val)) {
             $path = $pathNames[$cacheKey];
             $this->cheapCache->set($path, 'stat', $val);
             if (isset($val['sha1'])) {
                 // some backends store SHA-1 as metadata
                 $this->cheapCache->set($path, 'sha1', array('hash' => $val['sha1'], 'latest' => $val['latest']));
             }
         }
     }
     wfProfileOut(__METHOD__ . '-' . $this->name);
     wfProfileOut(__METHOD__);
 }
Example #5
0
 /**
  * @covers BagOStuff::getMulti
  */
 public function testGetMulti()
 {
     $value1 = ['this' => 'is', 'a' => 'test'];
     $value2 = ['this' => 'is', 'another' => 'test'];
     $value3 = ['testing a key that may be encoded when sent to cache backend'];
     $value4 = ['another test where chars in key will be encoded'];
     $key1 = wfMemcKey('test1');
     $key2 = wfMemcKey('test2');
     // internally, MemcachedBagOStuffs will encode to will-%25-encode
     $key3 = wfMemcKey('will-%-encode');
     $key4 = wfMemcKey('flowdb:flow_ref:wiki:by-source:v3:Parser\'s_"broken"_+_(page)_&_grill:testwiki:1:4.7');
     $this->cache->add($key1, $value1);
     $this->cache->add($key2, $value2);
     $this->cache->add($key3, $value3);
     $this->cache->add($key4, $value4);
     $this->assertEquals([$key1 => $value1, $key2 => $value2, $key3 => $value3, $key4 => $value4], $this->cache->getMulti([$key1, $key2, $key3, $key4]));
     // cleanup
     $this->cache->delete($key1);
     $this->cache->delete($key2);
     $this->cache->delete($key3);
     $this->cache->delete($key4);
 }
Example #6
0
 public function getMulti(array $keys)
 {
     return $this->readStore->getMulti($keys);
 }
 /**
  * Get multiple items at once
  *
  * @author Władysław Bodzek <*****@*****.**>
  * @param $keys array List of keys
  * @return array Data associated with given keys, no data is indicated by "false"
  */
 public function getMulti($keys)
 {
     global $wgEnableMemcachedBulkMode;
     if (empty($wgEnableMemcachedBulkMode)) {
         return parent::getMulti($keys);
     }
     return $this->getMultiInternal($keys, true);
 }
 public function getMulti(array $keys, $flags = 0)
 {
     return $flags & self::READ_LATEST ? $this->writeStore->getMulti($keys, $flags) : $this->readStore->getMulti($keys, $flags);
 }