PHP File Cache function. For more information, see.
Php File Cache function. For more information, see.
The Code is as follows:
Function createHashDir ($ sign)
{
$ Md5 = md5 ($ sign );
If (! Is_dir (MB_CACHE) mkdir (MB_CACHE );
For ($ I = 1; $ I <= 4; $ I ++)
{
$ Dir. = $ md5 {$ I }.'/';
If (! Is_dir (MB_CACHE. $ dir ))
{
Mkdir (MB_CACHE. $ dir );
}
}
Return MB_CACHE. $ dir;
}
Function setCacheFile ($ data, $ sign = 'A', $ type = 'array', $ id = '')
{
$ CacheDir = $ this-> createHashDir ($ sign );
If (! Empty ($ data ))
{
$ Id = $ id? $ Id: $ sign;
$ CacheFile = $ cacheDir. $ id. '. php ';
$ Content = $ type = 'array '? Var_export ($ data, true): $ data;
File_put_contents ($ cacheFile ,' ');
}
}
Function getCacheFile ($ sign = 'A', $ id = '')
{
$ CacheDir = $ this-> createHashDir ($ sign );
$ Id = $ id? $ Id: $ sign;
$ CacheFile = $ cacheDir. $ id. '. php ';
If (is_file ($ cacheFile) & amp; include_once ($ cacheFile ))
{
Return $ sign;
}
}
Function getCacheFilePath ($ sign = 'A', $ id = '')
{
$ CacheDir = $ this-> createHashDir ($ sign );
$ Id = $ id? $ Id: $ sign;
Return $ cacheDir. $ id. '. php ';
}
Function delCacheFile ($ sign = 'A ')
{
$ CacheDir = $ this-> createHashDir ($ sign );
$ Id = $ id? $ Id: $ sign;
$ CacheFile = $ cacheDir. $ id. '. php ';
$ This-> del_file ($ cacheFile );
}