保存要缓存的数据
这将保存到设置好的缓存目录(默认是/cache)下的data目录下

@param string $srcKey 要缓存的数据名(Key),取数据时要用到,可以是复杂名字
@param mixed $data 要缓存的数据,可以是复杂数据结构
@param int $expire 秒数
@return bool
3560
protected function doSet(string $srcKey, $data, int $expire = self::EXPIRE): bool
    {
        // 获取文件名与文件位置
        list ($key, $path, $sqlPath) = $this->getFile($srcKey);

        // 创建目录
        makeDir(dirname($path));

        // 保存缓存数据
        write($path, serialize($data), LOCK_EX);

        // 保存缓存的键
        write($sqlPath, $srcKey, LOCK_EX);

        // 取出目录,修改,保存回去
        $fileList = $this->getFileList();
        $fileList[$key] = $expire + time();
        $this->setFileList($fileList);

        return true;
    }
1292060
public static function cache($expire = 3600, $last_modify = null) {
        $time    = time();
        $date    = gmdate('D, d M Y H:i:s', $time) . ' GMT';
        $headers = [
            'Age'           => $expire,
            'Date'          => $date,
            'Expires'       => gmdate('D, d M Y H:i:s', $time + $expire) . ' GMT',
            'Cache-Control' => 'public, must-revalidate, max-age=' . $expire,
            'Pragma'        => 'cache'
        ];
        if ($last_modify) {
            $ldate                    = @gmdate('D, d M Y H:i:s', $last_modify) . ' GMT';
            $headers['Last-Modified'] = $ldate;
        }
        foreach ($headers as $header => $val) {
            @header($header . ': ' . $val);
        }
    }
493390
public static function forever($key, $data)
    {
        if (is_callable($data)) {
            $content = $data();
        } else {
            $content = $data;
        }

        $meta['__bow_meta'] = ['expire_at' => '+'];

        $meta['content'] = $content;

        return (bool) file_put_contents(
            static::makeHashFilename($key, true),
            serialize($meta)
        );
    }
1293617
protected function write(array $keys, $expire = null)
    {
        foreach ($keys as $k => $v) {
            apc_store($k, $v, $expire);
        }

        return true;
    }
778027
public static function encrypt($data,$key,$expire=0){
        if(empty(self::$handler)){
            self::init();
        }
        $class  =   self::$handler; 
        return $class::encrypt($data,$key,$expire);
    }
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);
	}
28932
public function store(Memento\Key $key, $value, $expires = null, $ttl = null)
    {
        $this->__connect($key);

        $hash = null;

        // if no expires specified use default of 5 minutes
        if (!is_numeric($expires)) {
            $expires = self::DEFAULT_EXPIRES;
        }

        // ttl is when the cache is actually okay for deletion
        if (!is_numeric($ttl)) {
            $ttl = $expires;
        }

        // convert to absolute time
        $expires = $expires + time();
        $ttl = $ttl + time();

        // handle arguments based on group or single key
        if ($this->groupKey) {
            $hash = array(
                $this->groupKey->getKey(),
                Memento\Hash::FIELD_VALID,
                serialize(true),
                $key->getKey(),
                serialize($value),
                Memento\Hash::FIELD_EXPIRES,
                $expires,
                Memento\Hash::FIELD_TTL,
                $ttl,
            );
        } else {
            $hash = array(
                $key->getKey(),
                array(
                    Memento\Hash::FIELD_DATA  => serialize($value),
                    Memento\Hash::FIELD_VALID => serialize(true),
                    Memento\Hash::FIELD_EXPIRES  => $expires,
                    Memento\Hash::FIELD_TTL => $ttl,
                )
            );
        }

        if (!is_array($hash)) {
            return false;
        }

        if ($success = call_user_func_array(array($this->redis, 'hmset'), $hash)) {
            $this->setExpires($key, $ttl); // actual redis expires uses ttl value
        }

        return $success;
    }
489211
public function expireAfter($key, $expire = 0)
    {
        $val = $this->mem->get($key);

        if (isset($val)) {
            return $this->set($key, $val, $expire);
        }

        return false;
    }
296103
protected function processGetResult($key, $result, $expire, $fn)
    {
        if (false === $result && ($expire || $fn)) {
            // Avoid using null as expire second, for null will be convert to 0
            // which means that store the cache forever, and make it hart to debug.
            if (!is_numeric($expire) && $fn) {
                throw new \InvalidArgumentException(sprintf(
                    'Expire time for cache "%s" must be numeric, %s given',
                    $key,
                    is_object($expire) ? get_class($expire) : gettype($expire)
                ));
            }

            // Example: get($key, function(){});
            if ($expire && !$fn) {
                $fn = $expire;
                $expire = 0;
            }

            $result = call_user_func($fn, $this->wei, $this);
            $this->set($key, $result, $expire);
        }
        return $result;
    }
694969
protected function saveAccessToken($token, $expire)
    {
        $data   = ['token' => $token, 'expire' => intval($expire), 'time' => time()];
        return ($this->getFileSystem()->put($this->getTokenFilePath(), json_encode($data), true) > 0);
    }
217956
public function storageLogin($key, $data, $expire = 0)
    {
        $ticket = md5(time() . rand(1000, 9999) . serialize($data));
        $key = $this->getKey($key);
        
        // 设置Cookie
        Cookie::set($key, $ticket, $expire);
        
        // 缓存数据
        Cache::set($ticket, $data, $expire);
    }
138516
private function pack($data, $expire)
    {

        if ($data === '') {
            return '';
        }

        $cookie_data = array();
        $cookie_data['value'] = $data;
        $cookie_data['expire'] = $expire;
        return json_encode($cookie_data);
    }
135286
protected function cacheData($key, $data, $config = [])
    {
        $this->cache->set($key, $data, $config['expire']);
    }
374508
public function set($key, $value = null, $expiration = 0)
    {
        if (apc_store($key, $value, ($expiration ? $expiration : null))) {
            $expiration = (empty ($expiration)) ? 0 : $expiration;

            // Prepare Listing
            $newListing = array(
                'key'        => ( string )$key,
                'expiration' => ( int )$expiration,
                'updated'    => ( string )date('Y-m-d H:i:s')
            );

            if (isset ($this->cacheListing [$key])) {
                $this->cacheListing [$key] = array_merge($this->cacheListing [$key], $newListing);
            } else {
                $newListing ['created']    = $newListing ['updated'];
                $this->cacheListing [$key] = $newListing;
            }

            $this->saveCacheListing();

            return true;
        }

        return false;
    }
884127
protected function doSet(string $key, $data, int $expire = self::EXPIRE): bool
    {
        /**
         * @var $handle \Memcache|\Memcached
         */
        $handle = $this->_handle;

        // 缓存数据
        return $handle->set($key, $data, MEMCACHE_COMPRESSED, $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;
        }
    }
866549
public function set($name, $value,$expire=null) {
        $data   =  serialize($value);
        $name   =  $this->options['prefix'].addslashes($name);
        N('cache_write',1);
        if( C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) {
            //数据压缩
            $data   =   gzcompress($data,3);
        }
        if(C('DATA_CACHE_CHECK')) {//开启数据校验
            $crc  =  md5($data);
        }else {
            $crc  =  '';
        }
        if(is_null($expire)) {
            $expire  =  $this->options['expire'];
        }
        $expire	    =   ($expire==0)?0: (time()+$expire) ;//缓存有效期为0表示永久缓存
        $result     =   $this->handler->query('select `cachekey` from `'.$this->options['table'].'` where `cachekey`=\''.$name.'\' limit 0,1');
        if(!empty($result) ) {
        	//更新记录
            $result  =  $this->handler->execute('UPDATE '.$this->options['table'].' SET data=\''.$data.'\' ,datacrc=\''.$crc.'\',expire='.$expire.' WHERE `cachekey`=\''.$name.'\'');
        }else {
        	//新增记录
             $result  =  $this->handler->execute('INSERT INTO '.$this->options['table'].' (`cachekey`,`data`,`datacrc`,`expire`) VALUES (\''.$name.'\',\''.$data.'\',\''.$crc.'\','.$expire.')');
        }
        if($result) {
            if($this->options['length']>0) {
                // 记录缓存队列
                $this->queue($name);
            }
            return true;
        }else {
            return false;
        }
    }