article.auto_cache.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class article_auto_cache extends auto_cache{
  3. private $key = "article:news";
  4. public function load($param)
  5. {
  6. $page = $param['page'];
  7. $page_size = $param['page_size'];
  8. $this->key = $this->key."_".$page;
  9. $listmsg = $GLOBALS['cache']->get($this->key);
  10. if($listmsg === false||true)
  11. {
  12. $page = $page-1>0?($page-1)*$page_size:0;
  13. $page_size = $page_size>0?$page_size:15;
  14. $limit = "limit ".$page.",".$page_size;
  15. $affiche_sql = "select a.id,a.title,a.content,a.create_time from ".DB_PREFIX."article as a left join ".DB_PREFIX."article_cate as ac on ac.id = a.cate_id where a.is_delete = 0 and a.is_effect = 1 and ac.type_id = 4 order by a.sort desc,a.create_time desc ".$limit;
  16. $affiche = $GLOBALS['db']->getAll($affiche_sql,true,true);
  17. $listmsg = array();
  18. foreach ( $affiche as $k => $v )
  19. {
  20. $msg = array();
  21. $msg['title'] =$v['title'];
  22. $msg['url'] =url("article#show",array('id'=>$v['id']));
  23. $msg['create_time'] =$v['create_time'];
  24. $listmsg[] = $msg;
  25. }
  26. $GLOBALS['cache']->set($this->key,$listmsg);
  27. }
  28. $affiche_count = "select count(a.id) from ".DB_PREFIX."article as a left join ".DB_PREFIX."article_cate as ac on ac.id = a.cate_id where a.is_delete = 0 and a.is_effect = 1 and ac.type_id = 4 ";
  29. $rs_count = $GLOBALS['db']->getOne($affiche_count,true,true);
  30. $list = array();
  31. $list['listmsg'] = $listmsg;
  32. $list['rs_count'] = $rs_count;
  33. return $list;
  34. }
  35. public function rm($param)
  36. {
  37. $GLOBALS['cache']->rm($this->key);
  38. }
  39. public function clear_all()
  40. {
  41. $GLOBALS['cache']->rm($this->key);
  42. }
  43. }
  44. ?>