用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - php代码库

缓存相关

2016-06-20 作者: Youn举报

[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;
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...