Esempio n. 1
0
 function clean($basedir, $initdir = false, $filename = false)
 {
     if (strlen($filename)) {
         $basedir_version = eaccelerator_get($this->sid . $basedir);
         if ($basedir_version === null) {
             return true;
         }
         if ($initdir !== false) {
             $initdir_version = eaccelerator_get($basedir_version . "|" . $initdir);
             if ($initdir_version === null) {
                 return true;
             }
         } else {
             $initdir_version = "";
         }
         eaccelerator_rm($basedir_version . "|" . $initdir_version . "|" . $filename);
     } else {
         if (strlen($initdir)) {
             $basedir_version = eaccelerator_get($this->sid . $basedir);
             if ($basedir_version === null) {
                 return true;
             }
             eaccelerator_rm($basedir_version . "|" . $initdir);
         } else {
             eaccelerator_rm($this->sid . $basedir);
         }
     }
     return true;
 }
 /**
  * Delete cache from shared memory
  *
  * @param  string $sKey - file name
  * @return result of the operation
  */
 function delData($sKey)
 {
     eaccelerator_lock($sKey);
     eaccelerator_rm($sKey);
     eaccelerator_unlock($sKey);
     return true;
 }
Esempio n. 3
0
 public function delete($key)
 {
     if (DEBUG) {
         \Lysine\logger('cache')->debug('Eaccelerator delete key ' . (is_array($key) ? implode(',', $key) : $key));
     }
     $key = $this->makeKey($key);
     return eaccelerator_rm($key);
 }
 public function flush()
 {
     $v9b207167e5381c47682c6b4f58a623fb = eaccelerator_clear();
     $v14f802e1fba977727845e8872c1743a7 = eaccelerator_list_keys();
     foreach ($v14f802e1fba977727845e8872c1743a7 as $v3c6e0b8a9c15224a8228b9a98ca1531d) {
         eaccelerator_rm(substr($v3c6e0b8a9c15224a8228b9a98ca1531d['name'], 1));
     }
     return $v9b207167e5381c47682c6b4f58a623fb;
 }
Esempio n. 5
0
 public function delete($id, $tag = FALSE)
 {
     if ($id === TRUE) {
         return eaccelerator_clean();
     }
     if ($tag == FALSE) {
         return eaccelerator_rm($id);
     }
     return TRUE;
 }
 public function delete($id, $tag = FALSE)
 {
     if ($tag === TRUE) {
         Kohana::log('error', 'tags are unsupported by the eAccelerator driver');
         return FALSE;
     } elseif ($id === TRUE) {
         return eaccelerator_clean();
     } else {
         return eaccelerator_rm($id);
     }
 }
Esempio n. 7
0
 public function clean($group, $mode = null)
 {
     $keys = eaccelerator_list_keys();
     $secret = $this->_hash;
     if (is_array($keys)) {
         foreach ($keys as $key) {
             $key['name'] = ltrim($key['name'], ':');
             if (strpos($key['name'], $secret . '-cache-' . $group . '-') === 0 xor $mode != 'group') {
                 eaccelerator_rm($key['name']);
             }
         }
     }
     return true;
 }
 function destroy_all()
 {
     if (!function_exists('eaccelerator_list_keys')) {
         return;
     }
     $key_list = eaccelerator_list_keys();
     $key_length = strlen($this->key);
     foreach ($key_list as $key) {
         if (strpos($key['name'], $this->key) === 0) {
             eaccelerator_rm($key['name']);
             $this->remove(substr($key['name'], $key_length));
         }
     }
     $this->reset();
 }
Esempio n. 9
0
 /**
  * Destroy the data for a particular session identifier in the SessionHandler backend.
  *
  * @param   string  $id  The session identifier.
  *
  * @return  boolean  True on success, false otherwise.
  */
 public function destroy($id)
 {
     $sess_id = 'sess_' . $id;
     return eaccelerator_rm($sess_id);
 }
Esempio n. 10
0
 /**
  * Set expire time on each call since eAccelerator sets it on
  * cache creation.
  *
  * @param string $key        Cache key to expire.
  * @param integer $lifetime  Lifetime of the data in seconds.
  */
 protected function _setExpire($key, $lifetime)
 {
     if ($lifetime == 0) {
         // Don't expire.
         return;
     }
     $expire = eaccelerator_get($key . '_expire');
     // Set prune period.
     if ($expire + $lifetime < time()) {
         // Expired
         eaccelerator_rm($key);
         eaccelerator_rm($key . '_expire');
     }
 }
 public function rm($key)
 {
     return eaccelerator_rm($key);
 }
Esempio n. 12
0
 function delete($key, $time = 0)
 {
     return eaccelerator_rm($key);
 }
Esempio n. 13
0
 /**
  * Remove an item from the cache
  *
  * @access protected
  * @param string $var Cache key
  * @return bool True if the operation succeeded
  */
 function _delete($var)
 {
     return eaccelerator_rm($this->key_prefix . $var);
 }
  /**
   * Smarty Cache Handler<br>
   * utilizing eAccelerator extension (http://eaccelerator.net/HomeUk)<br>
   *
   * Name:     smarty_cache_eaccelerator<br>
   * Type:     Cache Handler<br>
   * Purpose:  Replacement for the file based cache handling of Smarty. smarty_cache_eaccelerator() is
   *           using Turck eaccelerator extension to minimize disk usage.
   * File:     cache.eaccelerator.php<br>
   * Date:     Dec 2, 2003<br>
   *
   * Usage Example<br>
   * <pre>
   * $smarty = new Smarty;
   * $smarty->cache_handler_func = 'smarty_cache_eaccelerator';
   * $smarty->caching = true;
   * $smarty->display('index.tpl');
   * </pre>
   *
   * @author   André Rabold
   * @version  RC-1
   *
   * @param    string   $action         Cache operation to perform ( read | write | clear )
   * @param    mixed    $smarty         Reference to an instance of Smarty
   * @param    string   $cache_content  Reference to cached contents
   * @param    string   $tpl_file       Template file name
   * @param    string   $cache_id       Cache identifier
   * @param    string   $compile_id     Compile identifier
   * @param    integer  $exp_time       Expiration time
   * @return   boolean                  TRUE on success, FALSE otherwise
   *
   * @link     http://eaccelerator.net/HomeUk
   *           (eaccelerator homepage)
   * @link     http://smarty.php.net/manual/en/section.template.cache.handler.func.php
   *           (Smarty online manual)
   */
  function smarty_cache_eaccelerator($action, &$smarty, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null)
  {
    if(!function_exists("eaccelerator")) {
      $smarty->trigger_error("cache_handler: PHP Extension \"eaccelerator\" (http://eaccelerator.net/HomeUk) not installed.");
      return false;
    }

    // Create unique cache id:
    // We are using smarty's internal functions here to be as compatible as possible.
    $_auto_id    = $smarty->_get_auto_id($cache_id, $compile_id);
    $_cache_file = substr($smarty->_get_auto_filename(".", $tpl_file, $_auto_id),2);
    $eaccelerator_id  = "smarty_eaccelerator|".$_cache_file;

    // The index contains all stored cache ids in a hierarchy and can be iterated later
    $eaccelerator_index_id = "smarty_eaccelerator_index";

    switch ($action) {

      case 'read':
        // read cache from shared memory
        $cache_content = eaccelerator_get($eaccelerator_id);
        if (!is_null($cache_content) && _eaccelerator_hasexpired($cache_content)) {
          // Cache has been expired so we clear it now by calling ourself with another parameter :)
          $cache_content = null;
          smarty_cache_eaccelerator('clear', $smarty, $cache_content, $tpl_file, $cache_id, $compile_id);
        }

        $return = true;
        break;

      case 'write':
        // save cache to shared memory
        $current_time = time();
        if (is_null($exp_time) || $exp_time < $current_time)
          $ttl = 0;
        else
          $ttl = $exp_time - time();

        // First run garbage collection
        eaccelerator_gc();

        // Put content into cache
        eaccelerator_lock($eaccelerator_id);
        eaccelerator_put($eaccelerator_id, $cache_content, $ttl);

        // Create an index association
        eaccelerator_lock($eaccelerator_index_id);
        $eaccelerator_index = eaccelerator_get($eaccelerator_index_id);
        if (!is_array($eaccelerator_index))
          $eaccelerator_index = array();
        $indexes = explode(DIRECTORY_SEPARATOR, $_cache_file);
        $_pointer =& $eaccelerator_index;
        foreach ($indexes as $index) {
          if (!isset($_pointer[$index]))
            $_pointer[$index] = array();
          $_pointer =& $_pointer[$index];
        }
        $_pointer = $eaccelerator_id;
        eaccelerator_put($eaccelerator_index_id, $eaccelerator_index, 0);
        eaccelerator_unlock($eaccelerator_index_id);

        eaccelerator_unlock($eaccelerator_id);
        break;

      case 'clear':
        // clear cache info
        eaccelerator_lock($eaccelerator_index_id);
        $eaccelerator_index = eaccelerator_get($eaccelerator_index_id);
        if (is_array($eaccelerator_index)) {
          if (empty($cache_id) && empty($compile_id) && empty($tpl_file)) {
            // clear all cache
            eaccelerator_lock($eaccelerator_id);
            _eaccelerator_clear_cache($eaccelerator_index);
            eaccelerator_unlock($eaccelerator_id);
            $eaccelerator_index = array();
          }
          else {
            // clear single file or cache group
            $indexes = explode(DIRECTORY_SEPARATOR, $_cache_file);
            if (is_null($tpl_file))
              array_pop($indexes);

            $_pointer =& $eaccelerator_index;
            $_failed = false;
            foreach ($indexes as $index) {
              if (!isset($_pointer[$index])) {
                $_failed = true;
                break;
              }
              $_pointer =& $_pointer[$index];
            }

            if (!$_failed) {
              if (is_array($_pointer)) {
                // Clear cache group
                _eaccelerator_clear_cache($_pointer);
              }
              else {
                // Clear single file
                eaccelerator_lock($_pointer);
                eaccelerator_rm($_pointer);
                eaccelerator_unlock($_pointer);
              }
              $_pointer = null;
            }
          }
        }
        eaccelerator_put($eaccelerator_index_id, $eaccelerator_index, 0);
        eaccelerator_unlock($eaccelerator_index_id);

        $return = true;
        break;

      default:
        // error, unknown action
        $smarty->trigger_error("cache_handler: unknown action \"$action\"");
        $return = false;
        break;
    }
    return $return;
  }
Esempio n. 15
0
/**
 * Remove a given key from the volatile/lossy cache.
 *
 * @param string key
 * @return boolean True on success, false on failure. NULL if no backend available.
 */
function unset_from_mem_cache($key)
{
    if (function_exists('apc_delete')) {
        return apc_delete($key);
    }
    if (function_exists('xcache_unset')) {
        return xcache_unset(gen_key_for_cache($key));
    }
    if (function_exists('eaccelerator_rm')) {
        return eaccelerator_rm(gen_key_for_cache($key));
    }
}
Esempio n. 16
0
 public function del($name)
 {
     return eaccelerator_rm($name);
 }
Esempio n. 17
0
  */
 public function set($name, $value, $expire = null)
 {
     N('cache_write', 1);
     if (is_null($expire)) {
 /**
  * Clears the cache.
  *
  * @return boolean true if ok, false otherwise
  */
 public static function clear()
 {
     switch (self::cacher()) {
         case 'apc':
             return apc_clear_cache('user');
         case 'xcache':
             for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) {
                 if (!xcache_clear_cache(XC_TYPE_VAR, $i)) {
                     return false;
                 }
             }
             return true;
         case 'eaccelerator':
             $infos = eaccelerator_list_keys();
             if (is_array($infos)) {
                 foreach ($infos as $info) {
                     // eaccelerator bug (http://eaccelerator.net/ticket/287)
                     $key = 0 === strpos($info['name'], ':') ? substr($info['name'], 1) : $info['name'];
                     if (!eaccelerator_rm($key)) {
                         return false;
                     }
                 }
             }
             return true;
     }
     return false;
 }
Esempio n. 19
0
 public function del($key, $tableName, $connectionResource)
 {
     return eaccelerator_rm($this->getRealKey($tableName, $key));
 }
Esempio n. 20
0
 function delete($key, $time = 0)
 {
     eaccelerator_rm($key);
     return true;
 }
Esempio n. 21
0
/**
 * Put data in the cache
 *
 * Adds data to whatever cache method we're using
 *
 * @param  string $key the cache data identifier
 * @param  mixed $value the value to be stored
 * @param  int $ttl how long are we going to cache this data (in seconds)
 * @return void
 * @since  0.1.0
 */
function smfapi_cachePutData($key, $value, $ttl = 120)
{
    global $boardurl, $sourcedir, $modSettings, $memcached;
    global $cache_hits, $cache_count, $db_show_debug, $cachedir;
    if (empty($modSettings['cache_enable']) && !empty($modSettings)) {
        return;
    }
    $cache_count = isset($cache_count) ? $cache_count + 1 : 1;
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count] = array('k' => $key, 'd' => 'put', 's' => $value === null ? 0 : strlen(serialize($value)));
        $st = microtime();
    }
    $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . strtr($key, ':', '-');
    $value = $value === null ? null : serialize($value);
    // eAccelerator...
    if (function_exists('eaccelerator_put')) {
        if (mt_rand(0, 10) == 1) {
            eaccelerator_gc();
        }
        if ($value === null) {
            @eaccelerator_rm($key);
        } else {
            eaccelerator_put($key, $value, $ttl);
        }
    } elseif (function_exists('mmcache_put')) {
        if (mt_rand(0, 10) == 1) {
            mmcache_gc();
        }
        if ($value === null) {
            @mmcache_rm($key);
        } else {
            mmcache_put($key, $value, $ttl);
        }
    } elseif (function_exists('apc_store')) {
        // An extended key is needed to counteract a bug in APC.
        if ($value === null) {
            apc_delete($key . 'smf');
        } else {
            apc_store($key . 'smf', $value, $ttl);
        }
    } elseif (function_exists('output_cache_put')) {
        output_cache_put($key, $value);
    } elseif (function_exists('xcache_set') && ini_get('xcache.var_size') > 0) {
        if ($value === null) {
            xcache_unset($key);
        } else {
            xcache_set($key, $value, $ttl);
        }
    } else {
        if ($value === null) {
            @unlink($cachedir . '/data_' . $key . '.php');
        } else {
            $cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>';
            $fh = @fopen($cachedir . '/data_' . $key . '.php', 'w');
            if ($fh) {
                // write the file.
                set_file_buffer($fh, 0);
                flock($fh, LOCK_EX);
                $cache_bytes = fwrite($fh, $cache_data);
                flock($fh, LOCK_UN);
                fclose($fh);
                // check that the cache write was successful; all the data should be written
                // if it fails due to low diskspace, remove the cache file
                if ($cache_bytes != strlen($cache_data)) {
                    @unlink($cachedir . '/data_' . $key . '.php');
                }
            }
        }
    }
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
    }
    return;
}
Esempio n. 22
0
 /**
  * Updates the appropriate cache file
  *
  * @param	string	title of the datastore item
  * @param	mixed	The data associated with the title
  *
  * @return	void
  */
 function build($title, $data)
 {
     $ptitle = $this->prefix . $title;
     eaccelerator_rm($ptitle);
     eaccelerator_put($ptitle, $data);
 }
Esempio n. 23
0
 /**
  * 
  * Deletes a cache entry.
  * 
  * @param string $key The entry ID.
  * 
  * @return void
  * 
  */
 public function delete($key)
 {
     if (!$this->_active) {
         return;
     }
     // modify the key to add the prefix
     $key = $this->entry($key);
     // remove from eaccelerator
     eaccelerator_rm($key);
 }
 public function del($id)
 {
     return eaccelerator_rm($id);
 }
Esempio n. 25
0
 /**
  * 删除缓存
  * @return true/false
  */
 public function delete($key)
 {
     return \eaccelerator_rm($key);
 }
Esempio n. 26
0
 public function rm($key, $type = '')
 {
     $this->type = $type;
     return eaccelerator_rm($this->_key($key));
 }
Esempio n. 27
0
function cache_put_data($key, $value, $ttl = 120)
{
    global $boardurl, $sourcedir, $modSettings, $memcached;
    global $cache_hits, $cache_count, $db_show_debug;
    if (empty($modSettings['cache_enable']) && !empty($modSettings)) {
        return;
    }
    $cache_count = isset($cache_count) ? $cache_count + 1 : 1;
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count] = array('k' => $key, 'd' => 'put', 's' => $value === null ? 0 : strlen(serialize($value)));
        $st = microtime();
    }
    $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . $key;
    $value = $value === null ? null : serialize($value);
    // The simple yet efficient memcached.
    if (function_exists('memcache_set') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
        // Not connected yet?
        if (empty($memcached)) {
            get_memcached_server();
        }
        if (!$memcached) {
            return;
        }
        memcache_set($memcached, $key, $value, 0, $ttl);
    } elseif (function_exists('eaccelerator_put')) {
        if (mt_rand(0, 10) == 1) {
            eaccelerator_gc();
        }
        if ($value === null) {
            @eaccelerator_rm($key);
        } else {
            eaccelerator_put($key, $value, $ttl);
        }
    } elseif (function_exists('mmcache_put')) {
        if (mt_rand(0, 10) == 1) {
            mmcache_gc();
        }
        if ($value === null) {
            @mmcache_rm($key);
        } else {
            mmcache_put($key, $value, $ttl);
        }
    } elseif (function_exists('apc_store')) {
        // An extended key is needed to counteract a bug in APC.
        if ($value === null) {
            apc_delete($key . 'smf');
        } else {
            apc_store($key . 'smf', $value, $ttl);
        }
    } elseif (function_exists('output_cache_put')) {
        output_cache_put($key, $value);
    }
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
    }
}
 /**
  * Set expire time on each call since memcache sets it on cache creation.
  *
  * @access private
  *
  * @param string  $key   Cache key to expire.
  */
 function _setExpire($key)
 {
     $lifetime = $this->_lifetime;
     $expire = eaccelerator_get($key . '_expire');
     // set prune period
     if ($expire + $lifetime < time()) {
         eaccelerator_rm($key);
         eaccelerator_rm($key . '_expire');
     } else {
         eaccelerator_put($key . '_expire', time());
     }
 }
Esempio n. 29
0
 /**
  * Deletes a value with the specified key from cache
  * This is the implementation of the method declared in the parent class.
  * @param string $key the key of the value to be deleted
  * @return boolean if no error happens during deletion
  */
 protected function deleteValue($key)
 {
     return eaccelerator_rm($key);
 }
Esempio n. 30
0
 /**
  * Delete a cache entry based on id
  *
  * @param   string   id 
  * @param   integer  timeout [Optional]
  * @return  boolean
  */
 public function delete($id)
 {
     return eaccelerator_rm($this->_sanitize_id($id));
 }