My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

DsCache—— PHP's Simple Cache Class

包括: 1. 文件缓存(serialfile、datafile、 htmlfile);
2. 内存缓存( phpmemcached、eaccelerator );
   关于几个文件缓存的说明:
     serialfile 采用序列化得方式, 可以缓存所有数据类型;
     datafile 可以缓存变量, 但不包括对象;
     htmlfile 字符串缓存, 用于生成静态页面;
   以上3种缓存现实方式不同, 使用时请按需求制定, 一般来说 默认的serialfile 功能和速度已经足够用了; 
   如需指定缓存类型, 在 $GLOBALS['DsCache'] 数组中加入如下: 'cache_type' => 'phpmemcached';  
  svn>= r52 之后,添加了 auto_split_dir 这个参数, 如果设置为 true, 程序自动分割目录, 防止单目录下文件超过 1000 之后,读效率底下的问题。 
  注: 如果缓存很多 > 10W, 则应该转换内存缓存, 或者选种适合小文件的文件系统。

使用说明( >= 2.2.r50 ):

  require_once 'DsCache/_cache.class.php';
  
   //文件缓存测试
   $GLOBALS['DsCache'] = array(
  	'cache_dir' => 'tmp', //缓存目录(必须)
  	'life_time' => 900, //全局缓存时间 900s.
  );
  $data = "cache 用得顶瓜瓜!!!~~~~";
  $life = 60; //指定单个缓存时间
  
  //得到缓存实例
  $cache = _cache::object();
  $cache->set('key1', $data); //缓存变量
   
  echo 'no.1: ', $cache->get('key1'); //得到缓存
  
  $cache->remove('key1'); //清除特定缓存文件
  echo 'no.2: ', var_export($cache->get('key1'), true);
  
  //$cache->clean(); //清空缓存目录
  
  //如果单个缓存需要指定时间,时间 $life 加在 set 方法的第三个参数, get 方法的第二个参数;
  //   最好两个方法都指定, 这样可以无痛切换缓存方式;

使用说明( >= 2.0.r31 and <= 2.2.r50 ):

   require_once 'Cache.class.php';
  //注: 文件缓存支持所有变量, 不包括对象(拖慢速度)
  $_config['DsCache'] = array(
          'cache_dir' => dirname(__FILE__).'/tmp', //缓存目录(必须),最好用绝对路径
          'life_time' => 900, //全局缓存时间, 默认15min
           'encoding_filename' => true, //用 md5 加密文件名, 默认打开
           'cache_dir_umask' => 0755, //建立子目录时的默认权限
           );
  
   Cache::set('cache key', $data); //缓存变量
   Cache::get('cache key'); //得到缓存
   Cache::remove('cache key'); //清除特定缓存文件
   Cache::clean(); //清空缓存目录 
Powered by Google Project Hosting