public function getExpressionDetailByEmotion($emotion) { $cache_id = "_model_expression"; if (($list = object_cache_get($cache_id)) === false) { $res = $this->getAllExpression(); $list = $res; object_cache_set($cache_id, $list); } return $list[$emotion]; }
public function _setWeiboCache($id, $data) { object_cache_set("weibo_" . $id, $data); return F('weibo_detail_' . $id, $data); }
/** * 缓存微博评论 * * 缓存的key的格式为: weibo_comment_微博评论ID. * * @param array $comment_list 微博评论ID列表, 或者微博评论详情列表. 如果为微博评论ID列表时, 本方法会首先获取微博评论详情列表, 然后缓存. */ public function setCommentObjectCache(array $comment_list) { if (!is_array($comment_list[0]) && !is_numeric($comment_list[0])) { return false; } if (is_numeric($comment_list[0])) { // 给定的是weibo_comment_id的列表. 查询weibo_comment详情 $map['comment_id'] = array('in', $comment_list); $map['isdel'] = 0; $comment_list = $this->where($map)->findAll(); } foreach ($comment_list as $v) { object_cache_set("weibo_comment_{$v['comment_id']}", $v); } return $comment_list; }
public function setUserTagObjectCache(array $uids) { if (!is_numeric($uids[0])) { return false; } $base_cache_id = 'user_tag_'; $uids = implode(',', $uids); $sql = "SELECT a.*,b.tag_name FROM {$this->tablePrefix}user_tag a LEFT JOIN {$this->tablePrefix}tag b ON b.tag_id=a.tag_id WHERE a.uid IN ( {$uids} ) ORDER BY a.user_tag_id ASC"; $res = $this->query($sql); // 格式化为: array($uid => $tags_array) // 注: 每人最多含有10个标签 $user_tags = array(); foreach ($res as $v) { if (count($user_tags[$v['uid']]) >= 10) { continue; } else { $user_tags[$v['uid']][] = $v; } } foreach ($user_tags as $k => $v) { object_cache_set($base_cache_id . $k, $v); } return $res; }
/** * 获取所有的"用户-用户组"关联关系 * * 本方法按照运行时缓存->文件缓存->数据库的顺序查询 * @param $do_format 是否将结果集格式化为array($uid => $user_group_link) */ public function getAllUserGroupLink($do_format = true) { $cache_id = '_model_user_group_link' . ($do_format ? '_1' : '_0'); if (($res = object_cache_get($cache_id)) === false) { if (($res = F($cache_id)) === false) { $temp = M('user_group_link')->findAll(); if ($do_format) { foreach ($temp as $v) { $res[$v['uid']][] = $v; } } else { $res = $temp; } unset($temp); F($cache_id, $res); } object_cache_set($cache_id, $res); } return $res; }
} else { $base_cache_id = 'user_weibo_count_'; } if (($res = object_cache_get($base_cache_id . $uid)) === false) { $this->setUserWeiboCount(array($uid), $type); $res = object_cache_get($base_cache_id . $uid); } return intval($res); } /** * 批量预设置用户的关注数的运行时缓存 */ public function setUserFollowingCount($uids) { if (!is_array($uids) || !is_numeric($uids[0])) {