Exemplo n.º 1
0
 public static function getIterator($pattern)
 {
     // sanity check pattern
     if (!preg_match('/^(.).+\\1[a-zA-Z]*$/', $pattern)) {
         throw new Exception('Cache iterator pattern doesn\'t appear to have matching delimiters');
     }
     // modify pattern to insert key prefix and isolate matches to this site
     $prefixPattern = preg_quote(static::getKeyPrefix());
     if ($pattern[1] == '^') {
         $pattern = substr_replace($pattern, $prefixPattern, 2, 0);
     } else {
         $pattern = substr_replace($pattern, '^' . $prefixPattern . '.*', 1, 0);
     }
     return CacheIterator::createFromPattern($pattern);
 }
 public function clearCacheTree($record, $key = null)
 {
     if (!$key) {
         $key = static::getCacheKey($record['Handle'], $record['ParentID'], $record['Site'] == 'Remote');
     }
     Cache::delete($key);
     // iterate child collections
     $childCollectionsKey = static::getCacheKey('.*', $record['ID'], $record['Site'] == 'Remote');
     foreach (CacheIterator::getIterator('|^' . $childCollectionsKey . '|') as $childCollection) {
         if ($childCollection['value']) {
             static::clearCacheTree($childCollection['value'], $childCollection['key']);
         }
     }
     // iterate child files
     $childFilesKey = SiteFile::getCacheKey($record['ID'], '.*');
     foreach (CacheIterator::getIterator('|^' . $childFilesKey . '|') as $childFile) {
         if ($childFile['value']) {
             Cache::delete($childFile['key']);
         }
     }
 }