PEAR: Cache_Lite is a good File Cache. if you need to use the file cache in your project, cache_lite is the first choice. PEAR: Cache_Lite is a good File Cache. if you need to use the file cache in your project, cache_lite is the first choice.
One of the reasons for using it all the time is that cache_lite can automatically clear expired and unupdated files. for example, if these files are self-written file caches, if they are not cleared, these files will always exist. Of course cache_lite can not only this benefit, you can go to the cache_lite official website to view more information: http://pear.php.net/manual/en/package.caching.cache-lite.intro.php
Cache_lite installation:
1. download the cache_lite package: http://pear.php.net/package/cache_lite/download. the latest version is 1.7.15.
2. download the PEAR package: Submit.
3. decompress the two installation packages and copy the files to the include directory.
./PEAR-1.9.4/PEAR.php./PEAR-1.9.4/PEAR5.php./Cache_Lite-1.7.15/Lite.php
4. the include directory contains the above three files, so that the installation is complete.
Cache_lite usage:
Cache_lite requires some parameters. for details, see Lite. in this php file, I like to create another class, set some common settings, call this new class, and reset individual settings according to the actual situation.
The following is your own cache class:
Path = $ cache_path; $ this-> option = $ cache_option; // file cache path $ this-> option ['cachedir'] = $ this-> path; // the group in which the cache is located. the default value is default $ this-> option ['group'] = isset ($ cache_option ['group'])? $ Cache_option ['group']: 'default'; // cache validity period, the default value is 3600 seconds. $ this-> option ['lifetime'] = isset ($ cache_option ['lifetime'])? $ Cache_option ['lifetime']: 3600; // whether to enable the inclusion of cache file names, $ this-> option ['filenameprotection '] = isset ($ cache_option ['filenameprotection']) is enabled by default. $ Cache_option ['filenameprotection ']: true; // whether to enable automatic clearing of expired cache. This function is enabled by default, this operation occurs when the new cache is written $ this-> option ['iciccleaningfactor '] = isset ($ cache_option ['automaticcleaningfactor'])? $ Cache_option ['iciccleaningfactor ']: 1; // whether to enable Recursive directory. by default, 1 is the recursive layer-1 Directory, 2 is a recursive 2-layer directory $ this-> option ['hasheddirectorylevel'] = isset ($ cache_option ['hasheddirectorylevel'])? $ Cache_option ['hasheddirectorylevel']: 0; // permission value used to create a directory when recursive directories are enabled, the default value is 0777 $ this-> option ['hasheddirectoryumask '] = isset ($ cache_option ['hasheddirectoryumask'])? $ Cache_option ['hasheddirectoryumask ']: 0777; $ this-> _ cache = new Cache_Lite ($ this-> option);} public function _ struct () {unset ($ this-> _ cache);} public function save_cache ($ cache_data, $ cache_id = '') {if (! File_exists ($ this-> path) {mkdir ($ this-> path, 0777, true);} return $ this-> _ cache-> save ($ cache_data, $ cache_id);} public function get_cache ($ cache_id) {$ result = $ this-> _ cache-> get ($ cache_id); return $ result;} public function delete_cache () {return $ this-> _ cache-> clean ();}}
This class basically sets the default initial values for some common parameters and resets them as needed.
Common cache_lite methods:
Cache_Lite: Cache_Lite ()-constructor Cache_Lite: get ()-test whether the cache exists and (if yes) return it Cache_Lite: save () -save data to a cache file Cache_Lite: remove ()-delete a cache file Cache_Lite: clean ()-Clear cacheCache_Lite: setToDebug ()-set to debug mode Cache_Lite :: setLifeTime ()-set the new lifecycle Cache_Lite: savemorycachingstate () -- Cache_Lite: getMemoryCachingState () -- Cache_Lite: lastModified ()-return the last cache update time. Cache_Lite: raiseError ()-trigger a PEAR error constructorCache_Lite: extendLife ()-reset the cache file modification time