Simple example php tutorial cache file generation technical example
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 );
}
}