这篇文章主要为大家详细介绍了php缓存相关简单示例,具有一定的参考价值,可以用来参考一下。
对php缓存相关简单示例感兴趣的小伙伴,下面一起跟随四海网的小编巴闭妹来看看吧!
/**
*
* @param
* @arrange (512.笔记) www.q1010.com
**/
function tag_mobile_content(array $opts = array())
{
$options = array('status' => 6);
extract($opts, EXTR_SKIP);
if (!empty($catid)) $options['catid'] = $catid;
if (!empty($modelid)) $options['modelid'] = $modelid;
if (isset($inslider)) $options['inslider'] = intval($inslider);
if (isset($thumb)) $options['thumb'] = intval($thumb);
if (!empty($published)) {
if (strpos($published, ',') === false) {
if (is_numeric($published) && strlen($published) < 4) {
$published = strtotime("-$published day");
$options['published_min'] = $published;
} else {
$options['published_min'] = $published;
$options['published_max'] = $published;
}
} elseif (preg_match("/^\s*([\d]{4}\-[\d]{1,2}\-[\d]{1,2})?\s*\,\s*([\d]{4}\-[\d]{1,2}\-[\d]{1,2})?\s*$/", $published, $m)) {
if ($m[1]) $options['published_min'] = $m[1];
if ($m[2]) $options['published_max'] = $m[2];
}
}
if (!empty($where)) $options['where'] = $where;
$pagesize = !empty($size) ? intval($size) : 0;
$page = isset($page) ? intval($page) : 1;
//return loader::model('mobile_content', 'mobile')->search($options, $page, $pagesize);
// @start tag_mobile_content 写入本地缓存
$options['pagesize'] = $pagesize;
$options['page'] = $page;
$key_md5 = md5(var_export($options, true));
//临时缓存key
$key = 'mobile_content_'.$key_md5;
//永久缓存key
$key_permanert = 'mobile_content_permanent_'.$key_md5;
//缓存更新中标识
$key_updating = 'mobile_content_updating_'.$key_md5;
$local = require(ROOT_PATH . 'config/localcache.php');
$cache = new cache($local);
$content = $cache->get($key);
if (empty($content) || $_GET['debug'] == 1) {
$content = $cache->get($key_permanert);
$content_updating = $cache->get($key_updating);
if(empty($content_updating) || $_GET['debug'] == 1)
{
$cache->set($key_updating, '1',2000);
$content = loader::model('mobile_content', 'mobile')->search($options, $page, $pagesize);
$cache->set($key, $content, 600+rand(0,600));
$cache->set($key_permanert, $content);
$cache->set($key_updating, '1', 1);
}
}
// @end tag_mobile_content 写入本地缓存
return $content;
}
本文来自:http://www.q1010.com/173/11062-0.html
注:关于php缓存相关简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。