예제 #1
0
function session_load($session_id)
{
    $data = file_get_contents('/var/lib/php/session2/sess_' . $session_id);
    return session_unserialize($data);
}
예제 #2
0
/**
 * Get a value/object from the global cache.
 * 
 * @param string $key the key of the value
 * @param mixed $default a default return value if the key can not be found in the cache
 * @return mixed The object from the cache or `$default`
 */
function globalcache_get($key, $default = false)
{
    if (!hook_already_fired(HOOK_POST_INIT)) {
        return $default;
    }
    global $CONFIG;
    try {
        if (!isset($CONFIG['globalcache']) || !isset($CONFIG['globalcache']['CACHE'])) {
            return $default;
        }
        switch ($CONFIG['globalcache']['CACHE']) {
            case globalcache_CACHE_OFF:
                return $default;
                break;
            case globalcache_CACHE_APC:
                $ret = apc_fetch($GLOBALS["globalcache_key_prefix"] . $key, $success);
                return $success ? $ret : $default;
                break;
            case globalcache_CACHE_ZEND:
                $ret = $GLOBALS["zend_cache_object"]->load(globalcache_cleanupkey($GLOBALS["globalcache_key_prefix"] . $key));
                return $ret === false ? $default : $ret;
                break;
            case globalcache_CACHE_EACCELERATOR:
                $ret = eaccelerator_get($GLOBALS["globalcache_key_prefix"] . md5($key));
                return is_null($ret) ? $default : $ret;
                break;
            case globalcache_CACHE_MEMCACHE:
                $ret = $GLOBALS["memcache_object"]->get($GLOBALS["globalcache_key_prefix"] . md5($key));
                return $ret === false ? $default : $ret;
                break;
            case globalcache_CACHE_DB:
                $ds = model_datasource($CONFIG['globalcache']['datasource']);
                try {
                    $ret = $ds->ExecuteScalar("SELECT cvalue FROM wdf_cache WHERE ckey=? AND (valid_until IS NULL OR valid_until>=" . $ds->Driver->Now() . ")", array(md5($key)));
                } catch (Exception $ex) {
                    return $default;
                }
                if ($ret === false) {
                    return $default;
                }
                return session_unserialize($ret);
                break;
        }
    } catch (Exception $ex) {
        WdfException::Log($ex);
        die($ex->__toString());
    }
    return $ret;
}
예제 #3
0
/**
 * Returns a value from the wdf cache.
 * 
 * There are multiple caches: SESSION and global.
 * Global cache required additional globalcache module to be loaded.
 * Will only consult globalcache if `$use_global_cache` is true and `$use_session_cache` is false or 
 * the object is not found in the SESSION cache
 * @param string $key Identifies what you want
 * @param mixed $default The default value you want if key is not present in the cache
 * @param bool $use_global_cache If true checks the global cache too (see globalcache module)
 * @param bool $use_session_cache If true checks the SESSION cache (that one is before the global cache)
 * @return mixed The value if found, else the default value
 */
function cache_get($key, $default = false, $use_global_cache = true, $use_session_cache = true)
{
    if ($use_session_cache && isset($_SESSION["system_internal_cache"][$key])) {
        return session_unserialize($_SESSION["system_internal_cache"][$key]);
    }
    if ($use_global_cache && system_is_module_loaded('globalcache')) {
        $res = globalcache_get($key, $default);
        if ($use_session_cache && $res !== $default) {
            $_SESSION["system_internal_cache"][$key] = session_serialize($res);
        }
        return $res;
    }
    return $default;
}