从opencart里面抠出来一个数据缓存类,看着感觉不错
来源:互联网 发布:nginx windows教程 编辑:程序博客网 时间:2024/05/16 09:08
class cache {
var $maxlifetime = 3600;
function cache() {
if (!is_writable(DIR_CACHE)) {
exit('Error: Could not write to cache directory!');
}
foreach (glob(DIR_CACHE . 'cache.*') as $file) {
$array = explode('.', end(explode('/', $file)));
if ($array[2] < time()) {
$this->delete($array[1]);
}
}
}
function set($key, $value) {
$this->delete($key);
$file = fopen(DIR_CACHE . 'cache.' . $key . '.' . (time() + $this->maxlifetime), 'a');
fwrite($file, serialize($value));
fclose($file);
}
function get($key) {
foreach (glob(DIR_CACHE . 'cache.' . $key . '.*') as $cache) {
$contents = fopen($cache, 'r');
$result = fread($contents, filesize($cache));
fclose($contents);
return unserialize($result);
}
}
function delete($key) {
foreach (glob(DIR_CACHE . 'cache.' . $key . '.*') as $file) {
unlink($file);
}
}
}
var $maxlifetime = 3600;
function cache() {
if (!is_writable(DIR_CACHE)) {
exit('Error: Could not write to cache directory!');
}
foreach (glob(DIR_CACHE . 'cache.*') as $file) {
$array = explode('.', end(explode('/', $file)));
if ($array[2] < time()) {
$this->delete($array[1]);
}
}
}
function set($key, $value) {
$this->delete($key);
$file = fopen(DIR_CACHE . 'cache.' . $key . '.' . (time() + $this->maxlifetime), 'a');
fwrite($file, serialize($value));
fclose($file);
}
function get($key) {
foreach (glob(DIR_CACHE . 'cache.' . $key . '.*') as $cache) {
$contents = fopen($cache, 'r');
$result = fread($contents, filesize($cache));
fclose($contents);
return unserialize($result);
}
}
function delete($key) {
foreach (glob(DIR_CACHE . 'cache.' . $key . '.*') as $file) {
unlink($file);
}
}
}
- 从opencart里面抠出来一个数据缓存类,看着感觉不错
- 感觉不错的一个帖子
- 今天看了正则表达式感觉不错
- 多继承类的虚表结构(感觉这个讲的不错,整理出来)
- 民间秘方,里面的方子都是一个老中医几十年的心血哦。(感觉不错就摘过来了)
- dataGridView1查询时从缓存dataset里面读取数据
- Input Attr : DataList,html5里面的知识点,感觉不错的
- C中打印二进制位数的一个例子----当初学习5的反码打印出来是-6的一个例子(感觉不错的)
- 感觉不错~~~
- 感觉不错!
- 感觉不错
- 感觉不错!
- 感觉不错。
- 感觉不错
- C# 网络编程专题,初看了一下,感觉不错
- 从缓存里面取图片
- 发现一个在线jpg png转ICO的网站,用着感觉不错
- 前两天写了一个ini文件解析类,感觉还不错,和大家分享一下:)
- 关于 stack overflow 的一点思考 chkstk
- 深入研究 STL Deque 容器
- CSS 简单顶部一层菜单
- 离职
- javascript 时间函数
- 从opencart里面抠出来一个数据缓存类,看着感觉不错
- 2007年8月14日 我的博客开通啦!~~
- jdbc连接mysql,死记就好了
- 一些生成静态页面的思路
- 数据库性能优化一例之Hash Join
- Oralce SQL过程初步
- Cannot forward after response has been committed
- 测试新人的感想
- test