Created
August 24, 2014 10:29
-
-
Save 599316527/bdeaff182e244da8eb4b to your computer and use it in GitHub Desktop.
PHP Cache Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 缓存类 | |
*/ | |
class Cache { | |
private $filename; | |
/** | |
* __construct | |
* @param String $cache_filename 缓存文件名 | |
*/ | |
function __construct($cache_filename) { | |
$this->filename = $cache_filename; | |
} | |
/** | |
* 写入缓存 | |
* @param Array $data 缓存数据 | |
* @return Int 写入字节数 | |
*/ | |
public function write($data) { | |
$ret = file_put_contents($this->filename, json_encode($data)); | |
return $ret; | |
} | |
/** | |
* 读取缓存 | |
* @return stdClass 缓存数据 | |
*/ | |
public function read() { | |
$content = file_get_contents($this->filename); | |
return json_decode($content, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment