[php]代码库
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;
}