edu_index_courses.auto_cache.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. class edu_index_courses_auto_cache extends auto_cache
  3. {
  4. private $key = "edu:index:courses:";
  5. //参数有:act,is_recommend ,limit
  6. public function load($param, $is_real = false)
  7. {
  8. if ($param['list_type'] != '') {
  9. $this->key .= $param['list_type'] . ":";
  10. }
  11. $this->key .= md5(serialize($param));
  12. $list = $GLOBALS['cache']->get($this->key);
  13. $key_bf = $this->key . '_bf';
  14. if ($list === false || $is_real) {
  15. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  16. if (!$is_ok) {
  17. $list = $GLOBALS['cache']->get($key_bf, true);
  18. } else {
  19. $where = " cou.is_effect = 1 and cou.is_delete = 0";
  20. if ($param['is_recommend'] == 1) {
  21. $where .= " and cou.is_recommend=1 ";
  22. }
  23. if ($param['limit'] > 0) {
  24. $param['limit'] = intval($param['limit']);
  25. $limit = " limit " . $param['limit'] . " ";
  26. } else {
  27. $limit = '';
  28. }
  29. if ($param['order'] != '') {
  30. $order = $param['order'];
  31. } else {
  32. $order = " order by cou.is_recommend desc,cou.sort desc,cou.id desc ";
  33. }
  34. $sql = "select cou.id,cou.title,cou.image from " . DB_PREFIX . "edu_courses as cou
  35. where " . $where . " " . $order . " " . $limit . "";
  36. $list = $GLOBALS['db']->getAll($sql, true, true);
  37. foreach ($list as $k => $v) {
  38. $list[$k]['image'] = get_spec_image($v['image']);
  39. }
  40. $GLOBALS['cache']->set($this->key, $list, 10, true);
  41. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  42. }
  43. }
  44. if ($list == false) {
  45. $list = array();
  46. }
  47. return $list;
  48. }
  49. public function rm($param)
  50. {
  51. $GLOBALS['cache']->rm($this->key);
  52. }
  53. public function clear_all()
  54. {
  55. $GLOBALS['cache']->rm($this->key);
  56. }
  57. }
  58. ?>