video_viewer.auto_cache.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. class video_viewer_auto_cache extends auto_cache{
  3. private $key = "video:viewer:";
  4. public function load($param)
  5. {
  6. $group_id = $param['group_id'];
  7. $page = $param['page'];
  8. $this->key .= $group_id . '_' . $page;
  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. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoViewerRedisService.php');
  17. $video_viewer_redis = new VideoViewerRedisService();
  18. if($group_id){
  19. $list = $video_viewer_redis->get_viewer_list($group_id,$page,100);
  20. foreach($list['list'] as $k=>$v){
  21. $list['list'][$k]['head_image'] = get_spec_image($v['head_image'],150,150);
  22. }
  23. }else{
  24. $list = array(
  25. 'list'=>array(),
  26. 'has_next'=>0,
  27. 'page'=>1,
  28. 'status'=>1
  29. );
  30. }
  31. $GLOBALS['cache']->set($this->key,$list,10,true);
  32. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  33. }
  34. }
  35. if ($list == false) $list = array();
  36. return $list;
  37. }
  38. public function rm()
  39. {
  40. $GLOBALS['cache']->clear_by_name($this->key);
  41. }
  42. public function clear_all()
  43. {
  44. $GLOBALS['cache']->rm($this->key);
  45. }
  46. }
  47. ?>