Skip to content

Instantly share code, notes, and snippets.

@599316527
Created August 24, 2014 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 599316527/bdeaff182e244da8eb4b to your computer and use it in GitHub Desktop.
Save 599316527/bdeaff182e244da8eb4b to your computer and use it in GitHub Desktop.
PHP Cache Class
<?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