设置cache

@param string $name
@param mixed $var
@param int
@param callable $expireCheck
@return boolean
缓存过期检查方法, 缓存过期(超过ttl)后, get时调用, 返回true表示缓存继续可用.
如checker($got_var, $time)
557602
public function set($name, $var, $ttl = 0, callable $expireCheck = null)
    {
        $res = $this->impl->save($name, serialize(array(
            $var,
            $ttl,
            $expireCheck,
            time(),
        )), is_null($expireCheck) ? $ttl : 0);
        return $res;
    }
763056
public function parseVarFunction($name,$varArray){
        //对变量使用函数
        $length = count($varArray);
        //取得模板禁止使用函数列表
        $template_deny_funs = explode(',',C('TMPL_DENY_FUNC_LIST'));
        for($i=0;$i<$length ;$i++ ){
            $args = explode('=',$varArray[$i],2);
            //模板函数过滤
            $fun = trim($args[0]);
            switch($fun) {
            case 'default':  // 特殊模板函数
                $name = '(isset('.$name.') && ('.$name.' !== ""))?('.$name.'):'.$args[1];
                break;
            default:  // 通用模板函数
                if(!in_array($fun,$template_deny_funs)){
                    if(isset($args[1])){
                        if(strstr($args[1],'###')){
                            $args[1] = str_replace('###',$name,$args[1]);
                            $name = "$fun($args[1])";
                        }else{
                            $name = "$fun($name,$args[1])";
                        }
                    }else if(!empty($args[0])){
                        $name = "$fun($name)";
                    }
                }
            }
        }
        return $name;
    }
83072
private static function trylock($name, $ttl)
    {
        if (!self::cmd('get', $name)) {
            self::cmd('set', $name, $ttl);
            $ret = false;
        } else {
            $ret = true;
        }
        self::status('set', $name);
        return $ret;
    }
580859
protected function check(string $name, string $check = ''): bool
    {
        return Arr::get($this->keyMap, "{$name}.checksum") === $this->generateNewChecksum($check);
    }
603420
public static function cache($name, $value = '', $expires = 0)
    {
        if (!$name || !is_string($name)) {
            self::setError('参数错误!');

            return false;
        }

        /** @var BaseDriver $cacheDriver */
        static $cacheDriver;

        if (!isset($cacheDriver)) {
            $cacheDriver = __NAMESPACE__ . '\\CacheDriver\\' . self::$CACHE_DRIVER . 'Driver';
            $cacheDriver = new $cacheDriver(__DIR__ . '/Cache/');
        }

        if (!$value && $value !== 0) {
            $value = $cacheDriver->_get($name);
            if (false == $value) {
                $value = null;
            }

            return $value;
        }

        $res = $cacheDriver->_set($name, $value, $expires);

        return $res ? true : false;
    }
1371909
public function set($name, $value, $expires = null)
    {
        $name = $this->getFullName($name);

        if (!is_array($value)) {
            $value = ['value' => (string) $value];
        }

        if (isset($expires)) {
            $value['expires'] = $expires;
        }

        parent::set($name, $value);

        return $this;
    }
405884
public function Set($name, $value, $expiry = self::OneYear, $path = '/', $domain = false)
    {

        $retval = false;
        if (!headers_sent()) {

            if ($domain === false)
                $domain = $_SERVER['HTTP_HOST'];

            if ($expiry === -1)
                $expiry = 1893456000; // Lifetime = 2030-01-01 00:00:00
            elseif (is_numeric($expiry))
                $expiry += time();
            else
                $expiry = strtotime($expiry);

            //echo "$name, $value, $expiry, $path, $domain";
            $retval = setcookie($name, $value, $expiry, $path, $domain);
            if ($retval)
                $_COOKIE[$name] = $value;

        }
        return $retval;
    }
362550
public static function set($name, $value, $expire = null){
        return self::driver()->set($name,$value,$expire);
    }
196002
public function set($name, $value, $expire) {
        if (is_null($expire)) {
            $expire = $this->options[ 'expire' ];
        }
        $filename = $this->getCacheFile($name);

        $data = serialize($value);
        if ($this->options[ 'data_compress' ] && function_exists('gzcompress')) {
            //数据压缩
            $data = gzcompress($data, 3);
        }
        $data = "<?php\n//" . sprintf('%012d', $expire) . $data . "\n?>";
        $result = file_put_contents($filename, $data);
        if ($result) {
            clearstatcache();
            return true;
        } else {
            return false;
        }
    }
1167368
public static function set($name, $value = '', $expire = 0)
    {
        !isset(self::$init) && self::init();

        if ($expire !== 0) {
            $expire = !empty(self::$config['expire']) ? $_SERVER['REQUEST_TIME'] + intval(self::$config['expire']) : 0;
        }

        if (is_string($name)) {
            setcookie(
                $name, $value, $expire, self::$config['path'],
                self::$config['domain'], self::$config['secure']
            );
        }

        if (is_array($name)) {
            foreach ($name as $item => $val) {
                setcookie(
                    $name, $val, $expire, self::$config['path'],
                    self::$config['domain'], self::$config['secure']
                );
            }
        }
    }
1049324
public function set(string $key, $value, int $expire = null): bool {
		if ($value instanceof Closure) {
			$value = $value();
		}
		return $this->driver->set($key, static::serialize($value), $expire ?? $this->expire);
	}
300025
public function has($name, $type = 'param', $checkEmpty = false)
    {
        if (empty($this->$type)) {
            $param = $this->$type();
        } else {
            $param = $this->$type;
        }
        // 按.拆分成多维数组进行判断
        foreach (explode('.', $name) as $val) {
            if (isset($param[$val])) {
                $param = $param[$val];
            } else {
                return false;
            }
        }
        return ($checkEmpty && '' === $param) ? false : true;
    }
642599
public function isSaved( string $name ): bool
	{
		if (realpath($this->cacheDir . DIRECTORY_SEPARATOR . $name) == false)
			return false;

		/** @var FileCacheStorage $storage */
		$storage = $this->load($name, true);
		return $storage->expires_at > time();
	}
159317
public function set($name, $value, $expire = null) {
        N('cache_write',1);
        if(is_null($expire)) {
            $expire  =  $this->options['expire'];
        }
        $name   =   $this->options['prefix'].$name;
        if($result = apc_store($name, $value, $expire)) {
            if($this->options['length']>0) {
                // 记录缓存队列
                $this->queue($name);
            }
        }
        return $result;
     }
439991
static public function set($name, $value, $expired = 0)
    {
        if (isset(Loader::$callback['CacheSet'])) {
            return call_user_func_array(Loader::$callback['CacheSet'], func_get_args());
        }
        $data = serialize(array('value' => $value, 'expired' => $expired > 0 ? time() + $expired : 0));
        return self::check() && file_put_contents(self::$cachepath . $name, $data);
    }
1305866
protected function cacheResults($name, Closure $callback)
    {
        return Cache::remember('cache::' . $name, $this->minutes, $callback);
    }
184322
public function get($name = ''){
            if(false === $var = xcache_get($name)){
                xcache_set($name, $var = parent::get($name));
            }

            return $var;
        }