예제 #1
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
  */
 protected final function primeFileCache(array $items)
 {
     $ps = $this->scopedProfileSection(__METHOD__ . "-{$this->name}");
     $paths = [];
     // list of storage paths
     $pathNames = [];
     // (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 file 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', ['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', ['map' => $val['xattr'], 'latest' => false]);
             }
         }
     }
 }
예제 #2
0
 public function testMcRouterSupport()
 {
     $localBag = $this->getMock('EmptyBagOStuff', ['set', 'delete']);
     $localBag->expects($this->never())->method('set');
     $localBag->expects($this->never())->method('delete');
     $wanCache = new WANObjectCache(['cache' => $localBag, 'pool' => 'testcache-hash', 'relayer' => new EventRelayerNull([])]);
     $valFunc = function () {
         return 1;
     };
     // None of these should use broadcasting commands (e.g. SET, DELETE)
     $wanCache->get('x');
     $wanCache->get('x', $ctl, ['check1']);
     $wanCache->getMulti(['x', 'y']);
     $wanCache->getMulti(['x', 'y'], $ctls, ['check2']);
     $wanCache->getWithSetCallback('p', 30, $valFunc);
     $wanCache->getCheckKeyTime('zzz');
 }