PHP文件缓存类库
<?php class File { private $_dir; const EXT = '.txt'; public function __construct() { $this->_dir = dirname(__FILE__) . '/files/'; } public function cacheData($key, $value = '', $cacheTime = 0) { $filename = $this->_dir . $key . self::EXT; if($value !== '') { // 将value值写入缓存 if(is_null($value)) { //$value 为null 将删除缓存 return @unlink($filename); } //目录不存在建立目录 $dir = dirname($filename); if(!is_dir($dir)) { mkdir($dir, 0777); } //设置定长缓存时间,保存到缓存文件中 $cacheTime = sprintf('%011d', $cacheTime); return file_put_contents($filename,$cacheTime . json_encode($value)); }
这是一个PHP文件缓存类库,需要的朋友可以下载使用
免责声明
本站所有资源均由网友贡献或各大下载网站转载。请自行检查软件的完整性!本站所有资源仅供学习参考。请不要将它们用于商业目的。否则,一切后果由您负责!如有侵权,请联系我们删除。联系方式:admin@php.cn
相关文章

07 Apr 2023
ThinkPHP是一个优秀的PHP开发框架。其核心缓存技术可以帮助提高网站的性能和响应速度。在使用ThinkPHP开发网站时,缓存文件路径的设置是一项非常重要的工作。本文将介绍如何在ThinkPHP中缓存文件路径。1. 理解ThinkPHP的缓存机制ThinkPHP提供了三种类型的缓存方式:文件缓存、Memcached缓存和Redis缓存。其中,文件缓存是最常见的缓存方式,但它

24 Dec 2024
将文件插入 MySQL 数据库:列类型和插入语句注意事项使用 Web 将文件插入 MySQL 数据库时...


Hot Tools

热门文章
丢失记录:Bloom&Rage -Corey和Dylan的锁组合
19 Feb 2025
手游攻略
Hello Kitty Island冒险:重新启动机器人任务演练
16 Feb 2025
手游攻略
王国来:拯救2-婚礼要买的衣服
05 Feb 2025
手游攻略
丢失的记录:Bloom&Rage-成就/奖杯指南
19 Feb 2025
手游攻略
王国来:拯救2-如何获得Comfrey
07 Feb 2025
手游攻略