select_weibo_digg.auto_cache.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class select_weibo_digg_auto_cache extends auto_cache{
  3. private $key = "select:weibo_digg:";
  4. public function load($param)
  5. {
  6. $this->key .= md5(serialize($param));
  7. $page=$param['page']>0?$param['page']:1;
  8. $page_size=$param['page_size']>0?$param['page_size']:20;
  9. $limit = (($page-1) * $page_size) . "," . $page_size;
  10. $weibo_id = intval($param['weibo_id']);
  11. $key_bf = $this->key.'_bf';
  12. $list = $GLOBALS['cache']->get($this->key,true);
  13. if ($list === false) {
  14. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  15. if(!$is_ok){
  16. $list = $GLOBALS['cache']->get($key_bf,true);
  17. }else{
  18. $weibo_info = $GLOBALS['db']->getRow("select w.id from ".DB_PREFIX."weibo as w where w.id = ".$weibo_id);
  19. if(!$weibo_info){
  20. $root['error'] = "动态不存在!";
  21. $root['status'] = 0;
  22. api_ajax_return($root);
  23. }
  24. //点赞列表
  25. $digg_list = $GLOBALS['db']->getAll("select wc.user_id,u.nick_name,u.head_image,u.is_authentication from ".DB_PREFIX."weibo_comment as wc
  26. left join ".DB_PREFIX."user as u on wc.user_id = u.id where wc.weibo_id = ".$weibo_id." and type = 2 order by wc.comment_id desc limit $limit");
  27. if($digg_list){
  28. foreach($digg_list as $k=>$v){
  29. if($v){
  30. $digg_list[$k]['head_image'] = get_spec_image($v['head_image']);
  31. }
  32. }
  33. }
  34. $list = $digg_list;
  35. $GLOBALS['cache']->set($this->key, $list, 10, true);
  36. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  37. //echo $this->key;
  38. }
  39. }
  40. if ($list == false) $list = array();
  41. return $list;
  42. }
  43. public function rm()
  44. {
  45. //$GLOBALS['cache']->clear_by_name($this->key);
  46. }
  47. public function clear_all()
  48. {
  49. //$GLOBALS['cache']->clear_by_name($this->key);
  50. }
  51. }
  52. ?>