+ -
当前位置:首页 → 问答吧 → php 静态缓存类

php 静态缓存类

时间:2007-09-09

来源:互联网

复制PHP内容到剪贴板
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 编辑 ]

作者: 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);           
       }
   }

作者: jlnuzjy   发布时间: 2007-09-08

晕 加个清理得函数

作者: jlnuzjy   发布时间: 2007-09-08

复制PHP内容到剪贴板
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

热门下载

更多