public function getBackend()
 {
     xcache_unset_by_prefix("cache");
     $backend = new \Cachet\Backend\XCache();
     $backend->setKeyBackend(new \Cachet\Backend\Memory());
     return $backend;
 }
Exemplo n.º 2
0
 public static function deactivate()
 {
     $pluginOpts = Typecho_Widget::widget('Widget_Options')->plugin('TypechoXcache');
     if ($pluginOpts->clearCacheAfterDisable == 'true') {
         xcache_unset_by_prefix($pluginOpts->{$prefix});
         return '缓存清空,成功关闭';
     }
     return '成功关闭';
 }
Exemplo n.º 3
0
 public function clear($prefix = '')
 {
     if (function_exists('xcache_unset_by_prefix')) {
         return xcache_unset_by_prefix($this->getNamespace() . $prefix);
     } else {
         // Since we can not clear by prefix, we just clear the whole cache.
         xcache_clear_cache(\XC_TYPE_VAR, 0);
     }
     return true;
 }
Exemplo n.º 4
0
 public function clear($prefix = '')
 {
     if (!function_exists('xcache_unset_by_prefix')) {
         function xcache_unset_by_prefix($prefix)
         {
             // Since we can't clear targetted cache, we'll clear all. :(
             xcache_clear_cache(XC_TYPE_VAR, 0);
         }
     }
     xcache_unset_by_prefix($this->getNamespace() . $prefix);
     return true;
 }
Exemplo n.º 5
0
 /**
  * Flush the cache.
  */
 function flush()
 {
     $prefix = INDEX_FILE_LOCATION . ':' . $this->getContext() . ':' . $this->getCacheId();
     if (function_exists('xcache_unset_by_prefix')) {
         // If possible, just flush the context
         xcache_unset_by_prefix(prefix);
     } else {
         // Otherwise, we need to do this manually
         for ($i = 0; $i < xcache_count(XC_TYPE_VAR); $i++) {
             $cache = xcache_list(XC_TYPE_VAR, $i);
             foreach ($cache['cache_list'] as $entry) {
                 if (substr($entry['name'], 0, strlen($prefix)) == $prefix) {
                     xcache_unset($entry['name']);
                 }
             }
         }
     }
 }
 /**
  * Clean the memory cache
  */
 function cache_clean()
 {
     if (!TP_ENABLE_CACHE) {
         return;
     }
     if ($this->memcache_working) {
         $this->memcache->flush();
     } elseif (function_exists('apc_clear_cache')) {
         apc_clear_cache('user');
     } elseif (function_exists('xcache_unset_by_prefix')) {
         @xcache_unset_by_prefix();
     }
     //TODO - clean on eaccelerator is not so clean...
 }
Exemplo n.º 7
0
 public function clear($prefix = '')
 {
     xcache_unset_by_prefix($this->getNamespace() . $prefix);
     return true;
 }
Exemplo n.º 8
0
 /**
  * (non-PHPdoc)
  * @see \parallely\TransportInterface::free()
  */
 public function free()
 {
     xcache_unset_by_prefix(self::PREFIX);
     return $this;
 }
Exemplo n.º 9
0
 /**
  * @see Cache_driver::clear()
  */
 public function clear($realm = '')
 {
     if (!function_exists('xcache_unset_by_prefix')) {
         function xcache_unset_by_prefix($prefix)
         {
             // Since we can't clear targetted cache, we'll clear all. :(
             xcache_clear_cache(XC_TYPE_VAR, 0);
         }
     }
     if (empty($realm)) {
         xcache_unset_by_prefix('');
     } else {
         xcache_unset_by_prefix($realm . '/');
     }
     return true;
 }
Exemplo n.º 10
0
 /**
  * (Plug-in replacement for memcache API) Remove all data from the persistant cache.
  */
 function flush()
 {
     xcache_unset_by_prefix('');
 }
function clear($prefix_ = null)
{
    if (null === $prefix_) {
        xcache_unset_by_prefix(COMPONENTS_CACHE_NAMESPACE);
    } else {
        xcache_unset_by_prefix(COMPONENTS_CACHE_NAMESPACE . "-{$prefix_}");
    }
}
Exemplo n.º 12
0
 protected function flushStore($cacheId)
 {
     $prefix = \Cachet\Helper::formatKey([$this->prefix, $cacheId]);
     xcache_unset_by_prefix($prefix);
 }
Exemplo n.º 13
0
 public function deleteByPrefix($key)
 {
     if ($key != null) {
         $result = xcache_unset_by_prefix($this->prefix . $key);
     } else {
         return false;
     }
 }
Exemplo n.º 14
0
 /**
  * Emulates `Memcache::flush`.
  */
 public function flush()
 {
     return xcache_unset_by_prefix(self::$key_prefix);
 }
Exemplo n.º 15
0
 public function truncate()
 {
     xcache_unset_by_prefix('');
     return TRUE;
 }
Exemplo n.º 16
0
 /**
  * Remove an item from the cache.
  *
  * @param  string  $key
  * @return bool
  */
 public function forget($key)
 {
     $pattern = $this->getPrefixWithLocale() . $key;
     if (strpos($pattern, '*') === false) {
         return xcache_unset($this->getPrefixWithLocale() . $key);
     }
     list($prefix) = explode('*', $pattern);
     return xcache_unset_by_prefix($prefix);
 }
Exemplo n.º 17
0
 /**
  * Delete cache object (or entire namespace if $name is null)
  *
  * This method will throw only logical exceptions.
  * In case of failures, it will return a boolean false.
  *
  * @param   string  $name    Name for cache element
  *
  * @return  bool
  * @throws \Comodojo\Exception\CacheException
  */
 public function delete($name = null)
 {
     if (!$this->isEnabled()) {
         return false;
     }
     $this->resetErrorState();
     if (empty($name)) {
         $delete = xcache_unset_by_prefix($this->getNamespace());
     } else {
         $delete = xcache_unset($this->getNamespace() . "-" . md5($name));
     }
     if ($delete === false) {
         $this->raiseError("Error writing cache (XCache), exiting gracefully");
         $this->setErrorState();
     }
     return $delete;
 }
Exemplo n.º 18
0
 /**
  * This function should clear the cache tree using the key array provided. If called with no arguments the entire
  * cache needs to be cleared.
  *
  * @param  null|array $key
  * @return bool
  */
 public function clear($key = null)
 {
     if (isset($key)) {
         $key = array();
     }
     $keyString = $this->makeKey($key);
     if (!$keyString) {
         return false;
     }
     return xcache_unset_by_prefix($keyString);
 }
Exemplo n.º 19
0
 /**
  * remove all data from cache by key prefix
  * @return true on success
  */
 function removeAllByPrefix($s)
 {
     return xcache_unset_by_prefix($s);
 }
Exemplo n.º 20
0
 /**
  * Flush all values 
  */
 public function flush()
 {
     xcache_unset_by_prefix($this->_prefix);
 }
Exemplo n.º 21
0
 /**
  *	Clear contents of cache backend
  *	@return bool
  *	@param $suffix string
  *	@param $lifetime int
  **/
 function reset($suffix = NULL, $lifetime = 0)
 {
     if (!$this->dsn) {
         return TRUE;
     }
     $regex = '/' . preg_quote($this->prefix . '.', '/') . '.+?' . preg_quote($suffix, '/') . '/';
     $parts = explode('=', $this->dsn, 2);
     switch ($parts[0]) {
         case 'apc':
         case 'apcu':
             $info = apc_cache_info('user');
             if (!empty($info['cache_list'])) {
                 $key = array_key_exists('info', $info['cache_list'][0]) ? 'info' : 'key';
                 $mtkey = array_key_exists('mtime', $info['cache_list'][0]) ? 'mtime' : 'modification_time';
                 foreach ($info['cache_list'] as $item) {
                     if (preg_match($regex, $item[$key]) && $item[$mtkey] + $lifetime < time()) {
                         apc_delete($item[$key]);
                     }
                 }
             }
             return TRUE;
         case 'redis':
             $fw = Base::instance();
             $keys = $this->ref->keys($this->prefix . '.*' . $suffix);
             foreach ($keys as $key) {
                 $val = $fw->unserialize($this->ref->get($key));
                 if ($val[1] + $lifetime < time()) {
                     $this->ref->del($key);
                 }
             }
             return TRUE;
         case 'memcache':
             $fw = Base::instance();
             foreach (memcache_get_extended_stats($this->ref, 'slabs') as $slabs) {
                 foreach (array_filter(array_keys($slabs), 'is_numeric') as $id) {
                     foreach (memcache_get_extended_stats($this->ref, 'cachedump', $id) as $data) {
                         if (is_array($data)) {
                             foreach (array_keys($data) as $key) {
                                 if (preg_match($regex, $key) && ($val = $fw->unserialize(memcache_get($this->ref, $key))) && $val[1] + $lifetime < time()) {
                                     memcache_delete($this->ref, $key);
                                 }
                             }
                         }
                     }
                 }
             }
             return TRUE;
         case 'wincache':
             $info = wincache_ucache_info();
             foreach ($info['ucache_entries'] as $item) {
                 if (preg_match($regex, $item['key_name']) && $item['use_time'] + $lifetime < time()) {
                     wincache_ucache_delete($item['key_name']);
                 }
             }
             return TRUE;
         case 'xcache':
             xcache_unset_by_prefix($this->prefix . '.');
             return TRUE;
         case 'folder':
             if ($glob = @glob($parts[1] . '*')) {
                 foreach ($glob as $file) {
                     if (preg_match($regex, basename($file)) && filemtime($file) + $lifetime < time()) {
                         @unlink($file);
                     }
                 }
             }
             return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function deleteAll()
 {
     xcache_unset_by_prefix($this->namespace . '_');
 }
Exemplo n.º 23
0
 /**
  * Remove items matching given prefix
  *
  * @param string $prefix
  * @return bool
  */
 public function clearByPrefix($prefix)
 {
     $prefix = (string) $prefix;
     if ($prefix === '') {
         throw new Exception\InvalidArgumentException('No prefix given');
     }
     $options = $this->getOptions();
     $namespace = $options->getNamespace();
     $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator() . $prefix;
     xcache_unset_by_prefix($prefix);
     return true;
 }
Exemplo n.º 24
0
 public function flushGroup($group)
 {
     return xcache_unset_by_prefix($this->getPrefix($group));
 }
Exemplo n.º 25
0
        $client->request($headers, '');
        $response = $client->response();
        if ($response['statusCode'] !== 200) {
            fprintf(STDERR, $response['stderr'] . PHP_EOL);
            exit(1);
        } else {
            fprintf(STDOUT, $response['body'] . PHP_EOL);
        }
    } catch (CommunicationException $ex) {
        fprintf(STDERR, $ex->getMessage() . PHP_EOL);
        exit(1);
    }
} else {
    $config = json_decode(file_get_contents(realpath(dirname(__FILE__)) . '/../configuration/config.json'), true);
    if ($config['XCACHE'] == 1) {
        xcache_unset_by_prefix($config['XPREFIX']);
        echo var_export('done', true) . PHP_EOL;
    }
}
/**
 * Note : Code is released under the GNU LGPL
 *
 * Please do not change the header of this file
 *
 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU
 * Lesser General Public License as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
Exemplo n.º 26
0
 public function unset_by_prefix($prefix_unset = '')
 {
     switch (self::$mode) {
         case CACHER_NO_CACHE:
             array_walk(self::$data, create_function('&$v,$k,$p', 'if(strpos($k, $p) === 0)$v = NULL;'), $this->prefix . $prefix_unset);
             return true;
             break;
         case CACHER_XCACHE:
             if (!function_exists('xcache_unset_by_prefix')) {
                 return false;
             }
             return xcache_unset_by_prefix($this->prefix . $prefix_unset);
             break;
     }
 }
Exemplo n.º 27
0
 /**
  * Delete all values in cache by prefix.
  *
  * This function does not work with all caching engines and should not
  * be relied on! It can help clearing stale caches, but caching in
  * general caching should try to be independent of this function. At
  * this point, only xcache and the file cache support this feature.
  *
  * @param string $key
  */
 public static function clearCacheByPrefix($key)
 {
     if (-1 == self::$API) {
         return;
     }
     $key = self::$basekey . strtr($key, ':', '-');
     switch (self::$API) {
         case 5:
             // memcached doesn't support deleting by prefix :(
             //
             // it is possible to get a list of all keys
             // from the server, but that function is not
             // even guaranted to return all keys, so the
             // user will just have to live with stale cache
             // here for now.
             //
             // we could also flush here, but that would be
             // quite volatile behavior
             break;
         case 4:
             // memcache doesn't support deleting by prefix :(
             // see above.
             break;
         case 1:
             // apc doesn't support deleting by prefix :(
             break;
         case 3:
             // zend doesn't support deleting by prefix :(
             break;
         case 2:
             xcache_unset_by_prefix($key);
             break;
         case 0:
             // Glob using the prefix and unlink all hits.
             foreach (glob(self::$cachedir . '/data_' . $key . '*.php') as $filename) {
                 @unlink($filename);
             }
             break;
     }
 }
Exemplo n.º 28
0
 public function cleanup()
 {
     xcache_unset_by_prefix(self::CACHE_PREFIX . (empty($this->_config['store_prefix']) ? '' : $this->_config['store_prefix'] . ':'));
 }
Exemplo n.º 29
0
    $workerState->counter = new \Cachet\Counter\APC();
    $workerState->counter->locker = new \Cachet\Locker\Semaphore();
}, 'test' => function ($workerState) use($config) {
    for ($i = 0; $i < $config->counterRuns; $i++) {
        $workerState->counter->increment('count');
    }
}, 'check' => function ($workers, $responses, $parentState) use($config) {
    $count = apc_fetch('counter/count');
    $expected = $config->workerCount * $config->counterRuns;
    if ($count != $expected) {
        return [false, "Count was {$count}, expected {$expected}"];
    } else {
        return [true];
    }
}], 'xcacheCounterTest' => ['setupParent' => function () {
    xcache_unset_by_prefix('counter/');
}, 'setupWorker' => function ($workerState) {
    $workerState->counter = new \Cachet\Counter\XCache();
}, 'test' => function ($workerState) use($config) {
    for ($i = 0; $i < $config->counterRuns; $i++) {
        $workerState->counter->increment('count');
    }
}, 'check' => function ($workers, $responses, $parentState) use($config) {
    $count = xcache_get('counter/count');
    $expected = $config->workerCount * $config->counterRuns;
    if ($count != $expected) {
        return [false, "Count was {$count}, expected {$expected}"];
    } else {
        return [true];
    }
}], 'memcacheBrokenCounterTest' => ['setupParent' => function ($parentState) {
Exemplo n.º 30
0
 public function clear()
 {
     return \xcache_unset_by_prefix('');
 }