ad_list.auto_cache.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. //底部文章
  3. class ad_list_auto_cache extends auto_cache
  4. {
  5. private $key = "ad:list:";
  6. public function load($place_id, $is_real)
  7. {
  8. $this->key .= $place_id;
  9. $key_bf = $this->key . '_bf';
  10. $ad_list = $GLOBALS['cache']->get($this->key, true);
  11. if ($ad_list === false || !$is_real) {
  12. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  13. if (!$is_ok) {
  14. return $GLOBALS['cache']->get($key_bf, true);
  15. }
  16. $now = to_date(NOW_TIME, 'Y-m-d H:i:s');
  17. $ad_list = $GLOBALS['db']->getAll("select title,url,image from " . DB_PREFIX . "ad where place_id=" . $place_id . " and begin_time < '" . $now . "' and end_time > '" . $now . "' order by sort asc");
  18. foreach ($ad_list as &$v) {
  19. $v['image'] = add_domain_url($v['image']);
  20. }
  21. $GLOBALS['cache']->set($this->key, $ad_list, 1800, true);
  22. $GLOBALS['cache']->set($key_bf, $ad_list, 86400, true);//备份
  23. }
  24. return $ad_list;
  25. }
  26. public function rm()
  27. {
  28. $GLOBALS['cache']->clear_by_name($this->key);
  29. }
  30. public function clear_all()
  31. {
  32. $GLOBALS['cache']->clear_by_name($this->key);
  33. }
  34. }