<?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)); }
This is a PHP file caching library, friends who need it can download and use
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article

12 Nov 2024
Memcache vs. Memcached: Choosing the Right PHP Library for Your Cache NeedsIn the realm of PHP caching libraries, Memcache and Memcached stand out...

19 Jan 2025
SFTP Libraries for .NET: A Comprehensive AnalysisWhen working with secure file transfer over SSH (SFTP) in .NET applications, choosing the right...

10 Nov 2024
How to Package an Android Library Project into a JAR FileWhen developing Android applications with multiple modules, sharing libraries between...

19 Dec 2024
Retrieving Symbol Information from a Shared LibraryWhen working with shared libraries (.so files), it often becomes necessary to examine their...

23 Oct 2024
This article presents two Python libraries (Paramiko and Twisted Conch) for secure file transfer using SFTP. It discusses their features and capabilities, helping developers choose the most suitable library based on their needs, such as simplicity, a

09 Nov 2024
Distinguishing "Memcache" and "Memcached" in PHPPHP offers two memcached libraries: memcache and memcached. Understanding their differences helps...


Hot Tools

PHP library for dependency injection containers
PHP library for dependency injection containers

A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking

Small PHP library for optimizing images
Small PHP library for optimizing images
