php 静态缓存类
时间:2007-09-09
来源:互联网
复制PHP内容到剪贴板
<?php
/**
*
* Cache::start();
*Cache::display();
*echo "你好";
*//etc ... what you want to output
*Cache::cache();
*Author jiayin 2007-09-08 20:00
*email : [[email protected]][email protected][/email]
*/
class Cache{
public static $expire = 900;
public static $basedir = '/tmp/';
public static function start(){
ob_start();
}
public static function end(){
ob_end_flush();
}
public static function getFilename(){
return self::basedir . md5($_SERVER['REQUEST_URI']));
}
pubic static function check(){
return !(file_exists(self::getFilename()) && ((time() - (filectime($tmpfilename))) < CACHE_EXPIRE));
}
pubic static function Cache(){
file_put_contents(self::getFilename() , ob_get_contents());
self::end();
exit;
}
public static function getCache(){
return file_get_contents(self::getFilename());
}
public static function diaplay(){
if(self::check()){
echo self::getCache();
self::end();
exit;
}
}
}
?>
[ 本帖最后由 forest 于 2007-9-11 12:57 编辑 ] PHP代码:
<?php
/**
*
* Cache::start();
*Cache::display();
*echo "你好";
*//etc ... what you want to output
*Cache::cache();
*Author jiayin 2007-09-08 20:00
*email : [[email protected]][email protected][/email]
*/
class Cache{
public static $expire = 900;
public static $basedir = '/tmp/';
public static function start(){
ob_start();
}
public static function end(){
ob_end_flush();
}
public static function getFilename(){
return self::basedir . md5($_SERVER['REQUEST_URI']));
}
pubic static function check(){
return !(file_exists(self::getFilename()) && ((time() - (filectime($tmpfilename))) < CACHE_EXPIRE));
}
pubic static function Cache(){
file_put_contents(self::getFilename() , ob_get_contents());
self::end();
exit;
}
public static function getCache(){
return file_get_contents(self::getFilename());
}
public static function diaplay(){
if(self::check()){
echo self::getCache();
self::end();
exit;
}
}
}
?>
作者: jlnuzjy 发布时间: 2007-09-08
注解
在应用的时候
可以根据自己的应用修改分目录
加个清理得类
public static funtion flush(){
if(file_exist(self::getFilename()))unlink(self::getFilename());
}
public static function flushAll(){
$d = dir(self::basedir);
while (false !== ($entry = $d->read())) {
if($entry != '.' && $entry != '..' && !is_dir($dir.$entry))unllink($dir.$entry);
}
}
在应用的时候
可以根据自己的应用修改分目录
加个清理得类
public static funtion flush(){
if(file_exist(self::getFilename()))unlink(self::getFilename());
}
public static function flushAll(){
$d = dir(self::basedir);
while (false !== ($entry = $d->read())) {
if($entry != '.' && $entry != '..' && !is_dir($dir.$entry))unllink($dir.$entry);
}
}
作者: jlnuzjy 发布时间: 2007-09-08
晕 加个清理得函数
作者: jlnuzjy 发布时间: 2007-09-08
复制PHP内容到剪贴板
<?php
/**
*
* Cache::start();
*Cache::display();
*echo "你好";
*//etc ... what you want to output
*Cache::cache();
*Author jiayin 2007-09-08 20:00
*email : [email][email protected][/email]
*/
class Cache{
public static $expire = 900;
public static $basedir = '/tmp/';
public static function start(){
ob_start();
}
public static function end(){
ob_end_flush();
}
public static function getFilename(){
return self::basedir . md5($_SERVER['REQUEST_URI']));
}
pubic static function check(){
return !(file_exists(self::getFilename()) && ((time() - (filectime($tmpfilename))) < CACHE_EXPIRE));
}
pubic static function Cache(){
file_put_contents(self::getFilename() , ob_get_contents());
self::end();
exit;
}
public static function getCache(){
return file_get_contents(self::getFilename());
}
public static function diaplay(){
if(self::check()){
echo self::getCache();
self::end();
exit;
}
}
}
?>
PHP代码:
<?php
/**
*
* Cache::start();
*Cache::display();
*echo "你好";
*//etc ... what you want to output
*Cache::cache();
*Author jiayin 2007-09-08 20:00
*email : [email][email protected][/email]
*/
class Cache{
public static $expire = 900;
public static $basedir = '/tmp/';
public static function start(){
ob_start();
}
public static function end(){
ob_end_flush();
}
public static function getFilename(){
return self::basedir . md5($_SERVER['REQUEST_URI']));
}
pubic static function check(){
return !(file_exists(self::getFilename()) && ((time() - (filectime($tmpfilename))) < CACHE_EXPIRE));
}
pubic static function Cache(){
file_put_contents(self::getFilename() , ob_get_contents());
self::end();
exit;
}
public static function getCache(){
return file_get_contents(self::getFilename());
}
public static function diaplay(){
if(self::check()){
echo self::getCache();
self::end();
exit;
}
}
}
?>
作者: wedypei 发布时间: 2007-09-10
我是菜鸟 还不懂怎么样啊
作者: asu530 发布时间: 2007-09-10
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28