<?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));
}
}
}
}
?>
memcache浅析
最新推荐文章于 2021-03-12 19:56:02 发布