Example #1
0
 public function add($key, $value, $ttl = 0, $ttl_compat = 0)
 {
     if ($ttl_compat != 0 && $ttl != $ttl_compat) {
         $ttl = $ttl_compat;
     }
     return apc_add($key, serialize($value), $ttl);
 }
Example #2
0
 public static function getInstance($section = null)
 {
     if (!$section) {
         $section = call_user_func(array(Kwf_Setup::$configClass, 'getDefaultConfigSection'));
     }
     if (!isset(self::$_instances[$section])) {
         $cacheId = 'config_' . str_replace('-', '_', $section);
         $configClass = Kwf_Setup::$configClass;
         if (extension_loaded('apc')) {
             $apcCacheId = $cacheId . getcwd();
             $ret = apc_fetch($apcCacheId);
             if (!$ret) {
                 //two level cache
                 $cache = Kwf_Config_Cache::getInstance();
                 $ret = $cache->load($cacheId);
                 if (!$ret) {
                     $ret = new $configClass($section);
                     $cache->save($ret, $cacheId);
                 }
                 apc_add($apcCacheId, $ret);
                 apc_add($apcCacheId . 'mtime', $cache->test($cacheId));
             }
         } else {
             $cache = Kwf_Config_Cache::getInstance();
             if (!($ret = $cache->load($cacheId))) {
                 $ret = new $configClass($section);
                 $cache->save($ret, $cacheId);
             }
         }
         self::$_instances[$section] = $ret;
     }
     return self::$_instances[$section];
 }
Example #3
0
 public function add($key, $value, $time = 0)
 {
     if (!_cacheStatus) {
         return FALSE;
     }
     apc_add($key, $value, $time);
 }
Example #4
0
 function __jax__loadClass($class_name)
 {
     global $__CLASS_AUTO_LOAD_CLASS_PATHS, $__CLASS_AUTO_LOAD_PATH_CACHE_TIMEOUT;
     $cacheKey = 'classAutoload:' . sha1($_SERVER['DOCUMENT_ROOT']) . ':' . $class_name;
     if (function_exists('apc_fetch')) {
         $path = @apc_fetch($cacheKey, $success);
     } else {
         $path = null;
         $success = false;
     }
     if (!$success) {
         foreach ($__CLASS_AUTO_LOAD_CLASS_PATHS as $dir) {
             $path = __jax__classAutoloadFindClassFile($class_name, $dir);
             if ($path !== false) {
                 if (function_exists('apc_add')) {
                     @apc_add($cacheKey, $path, $__CLASS_AUTO_LOAD_PATH_CACHE_TIMEOUT);
                 } else {
                     if (function_exists('apc_store')) {
                         @apc_store($cacheKey, $path, $__CLASS_AUTO_LOAD_PATH_CACHE_TIMEOUT);
                     }
                 }
                 break;
             }
         }
     }
     if ($path !== false) {
         include $path;
     }
 }
Example #5
0
 public function add($key, $value, $time = 0)
 {
     if (!CACHE_STATUS) {
         return false;
     }
     apc_add($key, $value, $time);
 }
Example #6
0
	/**
	 * Method: create()
	 * 	Creates a new cache.
	 *
	 * @access public
	 * @param $data mixed (Required) The data to cache.
	 * @returns _boolean_ Whether the operation was successful.
	 */
	public function create($data)
	{
		$data = serialize($data);
		$data = $this->gzip ? gzcompress($data) : $data;

		return apc_add($this->id, $data, $this->expires);
	}
Example #7
0
 function add($key, &$data, $ttl = false)
 {
     if (!$expire) {
         $expire = 0;
     }
     return apc_add($key, $data, $expire);
 }
Example #8
0
 /**
  * Save the cacheListing as an apc listing
  *
  * Although there is the possibility to list the cache otherwise
  *
  * @return boolean
  */
 public function saveCacheListing() : bool
 {
     if (md5(json_encode($this->cacheListing)) === $this->md5Sum) {
         return false;
     }
     return apc_add('cacheListing', $this->cacheListing);
 }
 function __construct($service_name = NULL, $etcd_base = "/services")
 {
     $this->services = apc_fetch("sd_services");
     if ($this->services !== false) {
         return;
     }
     error_log("Fetching services from etcd");
     /* Allow specifying of service_name directly or via ENV before falling back to "mysql" */
     if ($service_name == NULL) {
         $this->service_name = getenv("SD_SERVICE_NAME") ? getenv("SD_SERVICE_NAME") : "mysql";
     } else {
         $this->service_name = $service_name;
     }
     /* Base URL for etcd requests */
     $this->etcd_base = $etcd_base;
     /* Get the service list */
     $this->get_service_list();
     /* Start getting some hosts */
     foreach ($this->service_list as $service) {
         $etcd_result = $this->etcd_get($service, "");
         if ($etcd_result->node->nodes) {
             foreach ($etcd_result->node->nodes as $node) {
                 $value = explode(":", $node->value);
                 $service_results[] = array("id" => basename($node->key), "host" => $value[0], "port" => $value[1]);
             }
             $this->services[] = array("name" => basename($service), "nodes" => $service_results);
         }
     }
     /* Save the services to apc */
     apc_add("sd_services", $this->services, 10);
 }
Example #10
0
 public function add($key, $value, $ttl = false)
 {
     if ($ttl === false) {
         $ttl = $this->ttl;
     }
     return apc_add($key, $value, $ttl);
 }
Example #11
0
 static function set($name, $value)
 {
     if (extension_loaded('memcache')) {
         if (!static::$obj) {
             static::$obj = new Memcache();
             static::$obj->connect('127.0.0.1', 11211) or die("memcache is enable but not work, 127.0.0.1 11211");
             static::$type = 'memcache';
         }
         if ($value) {
             static::$obj->set($name, $value, false, 0);
         } else {
             return static::$obj->get($name);
         }
     } elseif (extension_loaded('apc')) {
         static::$type = 'apc';
         if ($value) {
             apc_add($name, $value);
         } else {
             return apc_fetch($name);
         }
     } else {
         static::$file = $file = __DIR__ . '/../runtime/' . md5($name) . '.php';
         if (!$value) {
             if (!file_exists($file)) {
                 return false;
             }
             return unserialize(include $file);
         }
         $str = "<?php return '";
         $str .= serialize($value);
         $str .= "';";
         file_put_contents($file, $str);
     }
 }
Example #12
0
 /**
  * 当键名不存在时设置键值
  * @param string $key   键名
  * @param mixed $value  键值
  * @param int $time     过期时间,默认为-1,不设置过期时间;为0则设置为永不过期
  * @return boolean      是否成功
  */
 public function setnx($key, $value, $time = -1)
 {
     if ($time > 0) {
         return apc_add($key, self::setValue(['value' => $value, 'expire_time' => time() + $time]), $time);
     }
     return apc_add($key, self::setValue(['value' => $value, 'expire_time' => -1]));
 }
Example #13
0
 public function store($key, $value, $overwrite, $ttl = 0)
 {
     if ($overwrite) {
         return apc_store($key, $value, $ttl);
     } else {
         return apc_add($key, $value, $ttl);
     }
 }
Example #14
0
 static function saveValueToCache($valueKey, $valueData)
 {
     if (extension_loaded('apc') && ini_get('apc.enabled')) {
         return apc_add($valueKey, $valueData);
     } else {
         return false;
     }
 }
Example #15
0
 /**
  * Cache a variable in the data store.
  *
  * @param string $key - Store the variable using this name.
  * @param string $data - The variable to store.
  * @param int $ttl - Time To Live; store var in the cache for ttl seconds.
  * @param bool $overwrite
  *
  * @return boolean - Returns true on success or false on failure.
  */
 public static function store($key, $data, $ttl = 0, $overwrite = false)
 {
     if ($overwrite) {
         return apc_store($key, $data, $ttl);
     } else {
         return apc_add($key, $data, $ttl);
     }
 }
Example #16
0
 /**
  * @inheritdoc
  */
 public function set($name, $value, $duration = 300, $new = false)
 {
     if ($new === true) {
         return apc_add($name, $value, $duration);
     } else {
         return apc_store($name, $value, $duration);
     }
 }
Example #17
0
	static function add($key, $value, $ttl = null) {
		if (!$ttl) $ttl = APC_TTL;
		if (self::isAvailable()) {
			return apc_add(APC_PREFIX . $key, serialize($value), $ttl) === TRUE;
		} else {
			return false;
		}
	}
Example #18
0
 public function store($key, $var, $lifetime = 0, $overwrite = true)
 {
     if ($overwrite) {
         return apc_store($key, $var, $lifetime);
     } else {
         return apc_add($key, $var, $lifetime);
     }
 }
Example #19
0
function testKeyTypes()
{
    apc_add("keysarray", array(2 => 'two', '3' => 'three'));
    $arr = apc_fetch("keysarray");
    foreach (array(2, 3, '2', '3') as $k) {
        var_dump($arr[$k]);
    }
}
Example #20
0
 function driver_set($keyword, $value = "", $time = 300, $option = array())
 {
     if (isset($option['skipExisting']) && $option['skipExisting'] == true) {
         return apc_add($keyword, $value, $time);
     } else {
         return apc_store($keyword, $value, $time);
     }
 }
Example #21
0
 public function add($key, $var, $expire= 0, $options= array()) {
     $added= apc_add(
         $this->getCacheKey($key),
         $var,
         $expire
     );
     return $added;
 }
Example #22
0
 public function add($key, $data)
 {
     if ($this->is_apc) {
         $this->delete($key);
         return apc_add($key, $data, $this->getLiveTime());
     }
     return false;
 }
Example #23
0
 public function updateCounter(array $data)
 {
     $new = apc_add($this->valueKey($data), 0);
     if ($new) {
         apc_store($this->metaKey($data), json_encode($this->metaData($data)));
     }
     apc_inc($this->valueKey($data), $data['value']);
 }
function SetCachedObject($key, $value, $locale, $ttl = 0)
{
    global $subdomain;
    $tmp = $key . '_' . $locale;
    if (APC_INSTALLED) {
        apc_add($tmp, $value, $ttl);
    }
}
 /**
  * {@inheritDoc}
  */
 public function get($timestamp)
 {
     $key = sprintf('apc_inc_%d', $timestamp);
     if (apc_add($key, 0, $this->ttl)) {
         return 0;
     }
     return apc_inc($key);
 }
 /**
  * Saves an object into the cache.
  *
  * @author  Martin Helmich <*****@*****.**>
  * @version 2008-10-11
  * @access  public
  * @param   string $key      The key of the object. This key will be
  *                           used to retrieve the object from the cache.
  * @param   mixed  $object   The object that is to be stored in the
  *                           cache. Depending on the cacheing method, this
  *                           object should be serializable.
  * @param   bool   $override Determines whether to override the variable
  *                           in case it is already stored in cache.
  * @return  bool             TRUE on success, otherwise FALSE.
  */
 function save($key, $object, $override = false)
 {
     if ($override) {
         return apc_store($this->getCacheKey($key), $object);
     } else {
         return apc_add($this->getCacheKey($key), $object);
     }
 }
Example #27
0
 /**
  * @param string $name The param's name
  * @param mixed $value The param's value
  * @param int $timeout Timeout before auto deleting, in seconds
  * @param boolean $override If true the previous value will overrided if already exists.
  *
  * @return boolean
  */
 public function set($name, $value, $timeout = null, $override = true)
 {
     if ($override) {
         return apc_store($name, $value, $timeout);
     } else {
         return apc_add($name, $value, $timeout);
     }
 }
Example #28
0
 /**
  * Store data by key.
  *
  * @param string $key Key identifier.
  * @param string $data Data to store.
  * @param boolean $overwrite Whether to replace data if the key already exists.
  * @param boolean $sticky Whether to make the key "sticky".
  * @return boolean TRUE if successful, FALSE otherwise.
  */
 public function set($key, $data, $overwrite = false, $sticky = false)
 {
     $key = ($sticky ? self::CACHE_STICKY : '') . self::CACHE_PREFIX . $key;
     if ($overwrite) {
         return apc_store($key, $data);
     }
     return apc_add($key, $data);
 }
Example #29
0
 /**
  * Adds a new item that is to be cached
  *
  * @param string $key
  * @param mixed $data
  * @param bool $overwrite
  * @return bool
  */
 public function add($key, $data, $overwrite = false)
 {
     if ($overwrite == false) {
         return apc_add($key, $data, $this->ttl());
     } else {
         return apc_store($key, $data, $this->ttl());
     }
 }
Example #30
0
 /**
  * Sets a value to the variable store
  * @param string $key The key of the variable
  * @param mixed $value The value of the variable
  * @param integer $timeToLive Set to a number of seconds to make the variable expire in that amount of time
  * @return null
  */
 public function set($key, $value = null, $timeToLive = null)
 {
     if ($value === null && !is_array($key)) {
         apc_add($key, 0);
         apc_delete($key);
     } else {
         apc_store($key, $value, $timeToLive);
     }
 }