edu_course_category.auto_cache.php 2.3 KB

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