bannerpc_list.auto_cache.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class bannerpc_list_auto_cache extends auto_cache{
  3. private $key = "bannerpc:list:";
  4. public function load($params = array())
  5. {
  6. $type = $params['type'] ? intval($params['type']) : 0;
  7. $show_position = $params['show_position'] ? intval($params['show_position']) : 0;
  8. $this->key .= "{$type}_{$show_position}";
  9. $key_bf = $this->key.'_bf';
  10. $list = $GLOBALS['cache']->get($this->key,true);
  11. if ($list === false) {
  12. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  13. if(!$is_ok){
  14. $list = $GLOBALS['cache']->get($key_bf,true);
  15. }else{
  16. $sql = "select title,image,url from ".DB_PREFIX."index_image where `type`={$type} and show_position={$show_position} order by sort asc";
  17. $list = $GLOBALS['db']->getAll($sql,true,true);
  18. foreach($list as $k=>$v){
  19. $list[$k]['type'] = $v['type'];
  20. $list[$k]['url'] = $v['url'];
  21. $list[$k]['title'] = $v['title'];
  22. $list[$k]['image'] = get_spec_image($v['image']);
  23. }
  24. $GLOBALS['cache']->set($this->key, $list, 3600, true);
  25. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  26. //echo $this->key;
  27. }
  28. }
  29. return $list;
  30. }
  31. public function rm($param)
  32. {
  33. $GLOBALS['cache']->rm($this->key);
  34. }
  35. public function clear_all()
  36. {
  37. $GLOBALS['cache']->rm($this->key);
  38. }
  39. }
  40. ?>