中国设计秀欢迎投稿
中国设计秀设计资源站
平面设计 画册 VI欣赏 包装 CG-插画 搜索 个人网页 Alexa排名 CSS 建站资源 下载专区 JS特效 品牌服装 服装院校 专题欣赏 SEO 图标欣赏 专题
广州网站设计 维美网站建设 域名注册 虚拟主机 广州网站建设 广州网页设计 虚拟主机 域名注册 素材下载 广告服务 中国品牌形象设计 网站推广 家具中国
求创科技
中国设计秀
中国福网
金视觉
中国设计秀欢迎你
中国品牌形象设计网
中国设计秀
当前位置:网络学院首页 >> 编程开发 >> php >> PHP Page Cache 页面缓存类

PHP Page Cache 页面缓存类 (1)

来源:中国设计秀    作者:    点击:172     加入收藏    发表评论
0
顶一下
中资源

    一个PHP Page Cache 的页面缓存类,代码结构还不错,大家有需要可以拿来用。

PAGE_CACHE.PHP
<?php
/*  $cache = new Cache("../cache/",20); // 构造函数,创建缓存类对象
   ………………………………
   ………………………………
   ………………………………
    $cache->PutCache();  // 倒出缓存
*/
class Cache
{
    private  $CacheDir = ’Cache’;     /* 缓存目录 */
    private  $SetTimeOut = 10;        /* 缓存过期时间 */
    private  $SetExt = ’.cache’;      /* 缓存文件后缀名 */
    private  $CacheFileUrl = ’’;      /* 缓存文件所在地址 */
    private  $CacheConfigFile = ’’;  /* 缓存文件配置信息 */

    public  $LastUnixTimePoke = 0;   /* 上一次缓存的 Unix 时间戳 */
    public  $CurrentUnixTimePoke = 0;/* 当前缓存的 Unix 时间戳 */
    public  $NextUnixTimePoke = 0;   /* 下一次缓存的 Unix 时间戳 */
    public  $UnixNowToNext = 0;        /* 现在和下一次缓存相差的 Unix 时间戳 */

    public  $LastTimePoke = 0;   /* 上一次缓存的时间 */
    public  $CurrentTimePoke = 0;/* 当前缓存的时间 */
    public  $NextTimePoke = 0;   /* 下一次缓存的时间 */

    public  $DataLength = 0; /* 缓存区内容长度 */
    public  $CacheToPage = ’’; /* 缓存文件内容 */
    private  $SplitTeam = false;  /* 是否分组存放Cache文件 */

    public  $Cache = false;        /* 是否需要缓存,用户外界判断 */

  private  $_IsCache = false; /* 是否能够缓存 */

     public function Cache( $SetTimeOut = 20, $CacheDir = ’Cache’, $SplitTeam = false, $SetExt = ’.cache’)
    {
         $this->CacheDir =  $CacheDir;
         $this->SplitTeam =  $SplitTeam;
        if(!is_numeric( $SetTimeOut))
        {
             $this->ErrResponse(’缓存过期时间设置无效’);
            return false;
        } else {
             $this->SetTimeOut =  $SetTimeOut;
        }
         $this->SetExt =  $SetExt;

        /* 缓存开始 */
        ob_clean();
        ob_start();
        ob_implicit_flush(0);
         $this->CreateCache();
        return true;
    }

    private function CreateCache()
    {
         $_CacheFile = str_replace(’.’,’_’,basename( $_SERVER[’PHP_SELF’])) . ’_’ .
                      md5(basename( $_SERVER[’PHP_SELF’])) .  $this->SetExt;
         $_CacheConfig = str_replace(’.’,’_’,basename( $_SERVER[’PHP_SELF’])) . ’_’ . ’.cof’;

        if(!file_exists( $this->CacheDir))
        {      mkdir( $this->CacheDir,0777);
        }

        if( $this->SplitTeam)
        {
             $_CacheConfigDir =  $this->CacheDir . str_replace(’.’,’_’,basename( $_SERVER[’PHP_SELF’])) . ’_/’;
            if(!file_exists( $_CacheConfigDir))
            {
                mkdir( $_CacheConfigDir,0777);
            }
             $_CacheUrl =  $this->CacheDir .  $_CacheConfigDir .  $_CacheFile;
             $_CacheConfigUrl =  $this->CacheDir .  $_CacheConfigDir .  $_CacheConfig;
        } else {
             $_CacheUrl =  $this->CacheDir .  $_CacheFile;
             $_CacheConfigUrl =  $this->CacheDir .  $_CacheConfig;

[1] [2] [3] [4]
2007-09-13 16:22:00    出处:
热点文章/相关文章
关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明 | 网站公告 | 友情链接 | 留言 | 旧版入口