memcache浅析

<?php

class indexController extends Uhut{

protected $cache_on = true;
protected $cache_off = false;

//列表层,遍历所有分类和栏目
//flush掉
//遍历所有id 去flush掉
//指定分类和栏目去flush
//指定id获取,指定id的区间去flush掉
//一级分类极其子级别
//所有二级分类
//所有栏目包含其下级flush
	function indexAction(){

		//1.逻辑处理
		$cid_str = "1,2,3,4,5,6";
		if(empty($_GET['p']))$p = '1';
		//2.数据处理
		if($this->cache_on){
			//
			$colth_info = models_indexCache::getInstence()->get_colth_info();
			$list_info models_indexCache::getInstence()->get_news_list_info('newslistAction_cat_data_'.$cid.'_'.$p);
			if(!$colth_info){
				
				$colth_info = models_indexPro::getInstence()->get_colth_info($cid_str);
				models_indexCache::getInstence()->set_colth_info($colth_info);
			}
			if(!$list_info){
				$list_info = models_indexPro::getInstence()->get_list_info($where);
				models_indexCache::getInstence()->set_list_info($cid,$p,$list_info);
			}
		}else{
			$colth_info = models_indexPro::getInstence()->get_colth_info($cid_str);
		}
		$this->set('cloth_info',$cloth_info);
	}
}
//data层
class models_indexPro extends Models{


	final public static function getInstence(){
	
	}
	function get_colth_info($cid_str){

		$sql = "....";
		$result = $this->db->getAll($sql);
		//process
		$data = '';
		return $data;
	}
	function get_list_info($where){
		return $data;
	}
	
}
//cache层
class models_indexCache extends Models{

	protected $index_key = array(
							'indexAction_cloth_info'=>md5('indexAction_cloth_info'),
							'newslistAction_cat_data_分类id_页数'=>md5(),
							'newsindexAction_cata_data_栏目id_页数'=>md5(),
							'newsartAction_art_data_文章id'=>md5(),
							);
	protected $show_msg = false;
	protected $mem_time = 300;

	final public static function getInstence(){
	
	}
	function get_colth_info(){
		
		$key = $this->index_key->indexAction_cloth_info;
		return $this->mem->get($key);
	}

	function set_colth_info($colth_info){

		$key = $this->index_key->indexAction_cloth_info;
		$this->mem->set($key,$colth_info,0,$this->mem_time);

	}
	function get_news_list_info($key){
		$key = md5($key);
		return $this->mem->get($key);
	}
	function set_news_list_info($cid,$p,$news_list_info){

		$key = 'newslistAction_cat_data_'.$cid.'_'.$p;
		$this->mem->set($key,$news_list_info,0,$this->mem_tiem);
	}
	function get_index_key(){
		return $this->index_key;
	}

	function flush_index_key($show_msg){

		$this->show_msg = $show_msg;
		$index_key = (array)$this->index_key;
		foreach($index_key as $v){
			if($this->show_msg == true){
				echo "正在处理-----key值为:----".$v."-----处理结果:".$this->mem->del($v);
			}else{
				$this->mem->del($v);
			}
		}
		echo "清除缓存成功";
	}
	function flush_list_key($start_page,$end_page){
	
		$cid_arr = models_indexPro::getInstence()->get_cat_arr();
		$sql = "select count(*) from cms_message";
		$count = $this->db->count($sql);
		$totalpage = ceil($count/10);
		$i = $start_page;
		if($end_page > $totalpage){
			$end_page = $totalpage;
		}
		foreach($cid_arr as $v){
		
			for($i=1;$i<$end_page;$i++){
			
				$this->mem->del(md5('newslistAction_'.$v.'_'.$i));
			}
		}
	}
}
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值