Simple instance php Cache file generation technical instance. Simple instance php Tutorial cache file generation technical instance classCache {protected $ _ cacheDir; publicfunction _ construct () {$ this-_ cacheDir. cache;} publicfunctionsetCacheDir ($ c simple instance php Tutorial cache file generation technical instance
Class Cache
{
Protected $ _ cacheDir;
Public function _ construct ()
{
$ This-> _ cacheDir = "./cache ";
}
Public function setCacheDir ($ cacheDir)
{
If (empty ($ cacheDir )){
$ This-> _ cacheDir = $ this-> _ cacheDir;
} Else {
$ This-> _ cacheDir = $ cacheDir;
}
}
Public function getCache ($ name)
{
$ File_path = $ this-> _ cacheDir. '/namma_cache-'. $ name;
If (! File_exists ($ file_path ))
{
Return false;
}
$ Handle = @ fopen ($ file_path, 'RB ');
$ Data = @ fread ($ handle, filesize ($ file_path ));
Return $ this-> unformatData ($ data );
@ Flose ($ handle );
}
Public function setCache ($ name, $ data)
{
$ File_path = $ this-> _ cacheDir. '/namma_cache-'. $ name;
$ Data = $ this-> formatData ($ data );
$ Fp = fopen ($ file_path, 'w ');
Fwrite ($ fp, $ data );
Fclose ($ fp );
Return $ file_path;
}
Public function formatData ($ data)
{
Return serialize ($ data );
}
Public function unformatData ($ data)
{
Return unserialize ($ data );
}
}
Worker Cache file generation technical instance class Cache {protected $ _ cacheDir; public function _ construct () {$ this-_ cacheDir =. /cache;} public function setCacheDir ($ c...