PHP实战:php 写入缓存文件、读取缓存文件的函数代码
发布时间:2020-05-29 04:24:07 所属栏目:PHP 来源:互联网
导读:介绍《PHP实战:php 写入缓存文件、读取缓存文件的函数代码》开发教程,希望对您有用。
|
《PHP实战:php 写入缓存文件、读取缓存文件的函数代码》要点: 一、写结果缓存文件PHP教程
/**
* 写结果缓存文件
*
* @params string $cache_name
* @params string $caches
*
* @return
*/
function write_static_cache($cache_name,$caches)
{
if ((DEBUG_MODE & 2) == 2)
{
return false;
}
$cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';
$content = "<?phprn";
$content .= "$data = " . var_export($caches,true) . ";rn";
$content .= "?>";
file_put_contents($cache_file_path,$content,LOCK_EX);
}
二、读结果缓存文件PHP教程
/**
* 读结果缓存文件
*
* @params string $cache_name
*
* @return array $data
*/
function read_static_cache($cache_name)
{
if ((DEBUG_MODE & 2) == 2)
{
return false;
}
static $result = array();
if (!empty($result[$cache_name]))
{
return $result[$cache_name];
}
$cache_file_path = ROOT_PATH . '/temp/static_caches/' . $cache_name . '.php';
if (file_exists($cache_file_path))
{
include_once($cache_file_path);
$result[$cache_name] = $data;
return $result[$cache_name];
}
else
{
return false;
}
}
以上就是php 写入缓存文件、读取缓存文件内容的函数代码,需要的朋友可以参考一下.PHP教程 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
