user cache
This commit is contained in:
parent
f820f252e5
commit
5223d7140b
@ -233,11 +233,17 @@ abstract class BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//显示用户
|
//显示当前登录用户
|
||||||
protected function showUser()
|
protected function showUser()
|
||||||
{
|
{
|
||||||
|
$id = Session::get('user_id');
|
||||||
|
$user = Cache::get('user'.$id);
|
||||||
|
if(!$user){
|
||||||
//1.查询用户
|
//1.查询用户
|
||||||
$user = Db::name('user')->field('id,name,nickname,user_img,sex,auth,city,email,sign,point,vip,create_time')->where('id',Session::get('user_id'))->cache(600)->find();
|
$user = Db::name('user')->field('id,name,nickname,user_img,sex,auth,city,email,sign,point,vip,create_time')->find($id);
|
||||||
|
Cache::tag('user')->set('user'.$id,$user,600);
|
||||||
|
}
|
||||||
|
|
||||||
//2.将User变量赋给模板 公共模板nav.html
|
//2.将User变量赋给模板 公共模板nav.html
|
||||||
View::assign('user',$user);
|
View::assign('user',$user);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ class User extends BaseController
|
|||||||
$result = Db::name('user')
|
$result = Db::name('user')
|
||||||
->where('id',$userId)
|
->where('id',$userId)
|
||||||
->update(['user_img'=>$name_path]);
|
->update(['user_img'=>$name_path]);
|
||||||
|
Cache::tag(['user','tagArtDetail','tagArt'])->clear();
|
||||||
if($result) {
|
if($result) {
|
||||||
$res = ['status'=>0,'msg'=>'头像更新成功'];
|
$res = ['status'=>0,'msg'=>'头像更新成功'];
|
||||||
} else {
|
} else {
|
||||||
@ -139,7 +139,12 @@ class User extends BaseController
|
|||||||
public function home($id)
|
public function home($id)
|
||||||
{
|
{
|
||||||
//用户
|
//用户
|
||||||
|
$u = Cache::get('user'.$id);
|
||||||
|
if(!$u){
|
||||||
$u = Db::name('user')->field('name,nickname,city,sex,sign,user_img,point,vip,create_time')->cache(3600)->find($id);
|
$u = Db::name('user')->field('name,nickname,city,sex,sign,user_img,point,vip,create_time')->cache(3600)->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//用户发贴
|
//用户发贴
|
||||||
$arts = Db::name('user')->alias('u')->join('article a','u.id = a.user_id')->field('u.id,a.id,a.title,a.pv,a.is_hot,a.create_time,a.delete_time')->where('a.delete_time',0)->where('a.user_id',$id)->order(['a.create_time'=>'desc'])->cache(3600)->select();
|
$arts = Db::name('user')->alias('u')->join('article a','u.id = a.user_id')->field('u.id,a.id,a.title,a.pv,a.is_hot,a.create_time,a.delete_time')->where('a.delete_time',0)->where('a.user_id',$id)->order(['a.create_time'=>'desc'])->cache(3600)->select();
|
||||||
//用户回答
|
//用户回答
|
||||||
|
Loading…
Reference in New Issue
Block a user