CacheFile::get PHP Method

get() public method

读取缓存
public get ( string $name ) : mixed
$name string 缓存变量名
return mixed
    public function get($name)
    {
        $filename = $this->filename($name);
        if (!is_file($filename)) {
            return false;
        }
        N('cache_read', 1);
        $content = file_get_contents($filename);
        if (false !== $content) {
            $expire = (int) substr($content, 8, 12);
            if ($expire != 0 && time() > filemtime($filename) + $expire) {
                //缓存过期删除缓存文件
                unlink($filename);
                return false;
            }
            if (C('DATA_CACHE_CHECK')) {
                //开启数据校验
                $check = substr($content, 20, 32);
                $content = substr($content, 52, -3);
                if ($check != md5($content)) {
                    //校验错误
                    return false;
                }
            } else {
                $content = substr($content, 20, -3);
            }
            if (C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) {
                //启用数据压缩
                $content = gzuncompress($content);
            }
            $content = unserialize($content);
            return $content;
        } else {
            return false;
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Tests CacheFile->set()
  */
 public function testSet()
 {
     @unlink("/tmp/shindig/te/test");
     @rmdir("/tmp/shindig/te");
     $this->CacheFile->set("test", "testing");
     $this->assertEquals("testing", $this->CacheFile->get("test"));
     @unlink("/tmp/shindig/te/test");
     @rmdir("/tmp/shindig/te");
 }
All Usage Examples Of CacheFile::get