Exemplo n.º 1
0
 /**
  * Returns cache engine instance
  *
  * @param string $engine
  * @param array $config
  * @return W3_Cache_Base
  */
 function &instance($engine, $config = array())
 {
     static $instances = array();
     $instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
     if (!isset($instances[$instance_key])) {
         switch ($engine) {
             case W3_CACHE_MEMCACHED:
                 require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
                 $instances[$instance_key] =& W3_Cache_Memcached::instance($config['engine'], $config);
                 break;
             case W3_CACHE_APC:
                 require_once W3TC_LIB_W3_DIR . '/Cache/Apc.php';
                 $instances[$instance_key] =& new W3_Cache_Apc();
                 break;
             case W3_CACHE_FILE:
                 require_once W3TC_LIB_W3_DIR . '/Cache/File.php';
                 $instances[$instance_key] =& new W3_Cache_File($config);
                 break;
             case W3_CACHE_FILE_PGCACHE:
                 require_once W3TC_LIB_W3_DIR . '/Cache/File/PgCache.php';
                 $instances[$instance_key] =& new W3_Cache_File_PgCache($config);
                 break;
             default:
                 trigger_error('Incorrect cache engine', E_USER_WARNING);
                 require_once W3TC_LIB_W3_DIR . '/Cache/Base.php';
                 $instances[$instance_key] =& new W3_Cache_Base();
                 break;
         }
     }
     return $instances[$instance_key];
 }
 /**
  * Flushes cache
  */
 function flush()
 {
     static $cache_path = null;
     $cache =& $this->_get_cache();
     if (is_a($cache, 'W3_Cache_Memcached') && class_exists('Memcache')) {
         return $this->_memcached->flush();
     } elseif (is_a($cache, 'Minify_Cache_APC') && function_exists('apc_clear_cache')) {
         return apc_clear_cache('user');
     } elseif (is_a($cache, 'Minify_Cache_File')) {
         if (!is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
             $this->log(sprintf('Cache directory %s does not exists', W3TC_CACHE_FILE_MINIFY_DIR));
         }
         return w3_emptydir(W3TC_CACHE_FILE_MINIFY_DIR, array(W3TC_CACHE_FILE_MINIFY_DIR . '/index.php', W3TC_CACHE_FILE_MINIFY_DIR . '/.htaccess'));
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Check if memcache is available
  *
  * @param array $servers
  * @return boolean
  */
 function is_memcache_available($servers)
 {
     static $results = array();
     $key = md5(implode('', $servers));
     if (!isset($results[$key])) {
         w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Memcached.php');
         @($memcached = new W3_Cache_Memcached(array('servers' => $servers, 'persistant' => false)));
         $test_string = sprintf('test_' . md5(time()));
         $test_value = array('content' => $test_string);
         $memcached->set($test_string, $test_value, 60);
         $test_value = $memcached->get($test_string);
         $results[$key] = $test_value['content'] == $test_string;
     }
     return $results[$key];
 }
Exemplo n.º 4
0
 /**
  * Returns minify cache object
  *
  * @return object
  */
 function &_get_cache()
 {
     static $cache = array();
     if (!isset($cache[0])) {
         switch ($this->_config->get_string('minify.engine')) {
             case 'memcached':
                 require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php';
                 $this->_memcached =& W3_Cache_Memcached::instance($this->_config->get_string('minify.memcached.engine'), array('servers' => $this->_config->get_array('minify.memcached.servers'), 'persistant' => true));
                 $cache[0] =& new Minify_Cache_Memcache($this->_memcached);
                 break;
             case 'apc':
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/APC.php';
                 $cache[0] =& new Minify_Cache_APC();
                 break;
             default:
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php';
                 if (!is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
                     $this->log(sprintf('Cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR));
                 }
                 $cache[0] =& new Minify_Cache_File(W3TC_CACHE_FILE_MINIFY_DIR, $this->_config->get_boolean('minify.file.locking'));
                 break;
         }
     }
     return $cache[0];
 }