作者 liyuhang

gx

... ... @@ -72,9 +72,13 @@ class Common
* @method
*/
public static function get_user_cache($table,$id,$type = 'B'){
$data = [];
$cache = config('cache.user_is_cache');
if(isset($cache) && ($cache['is_cache'] == true)){
$key = 'cache_'.$table.'_'.$id.'_type';
$lists = Cache::store('file')->get($key);
return $lists;
$data = Cache::store('file')->get($key);
}
return $data;
}
/**
... ... @@ -84,8 +88,11 @@ class Common
* @method
*/
public static function set_user_cache($data = [],$table,$id,$type = 'B'){
$cache = config('cache.user_is_cache');
if(isset($cache) && ($cache['is_cache'] == true)){
$key = 'cache_'.$table.'_'.$id.'_type';
Cache::store('file')->set($key,$data,3600);
}
return true;
}
... ... @@ -96,11 +103,15 @@ class Common
* @method
*/
public static function del_user_cache($table,$id = '',$type = 'B'){
$cache = config('cache.user_is_cache');
if(isset($cache) && ($cache['is_cache'] == true)){
if (!empty($id)){
$key = 'cache_'.$table.'_'.$id.'_type';
}else{
$key = 'cache_'.$table.'_*';
}
return Cache::store('file')->pull($key);
Cache::store('file')->pull($key);
}
return true;
}
}
... ...
... ... @@ -117,6 +117,8 @@ class BlogLogic extends BaseLogic
}
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
//清除缓存
Common::del_user_cache($this->model->getTable(),$this->param['id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
... ... @@ -136,6 +138,8 @@ class BlogLogic extends BaseLogic
if($rs === false){
$this->fail('error');
}
//清除缓存
Common::del_user_cache($this->model->getTable(),$this->param['id']);
return $this->success();
}
/**
... ... @@ -145,19 +149,23 @@ class BlogLogic extends BaseLogic
* @method
*/
public function blog_info(){
//读取缓存
$info = Common::get_user_cache($this->model->getTable(),$this->param['id']);
if(!empty($info)){
return $this->success($info);
}
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
//获取分类名称
$cate = explode(',',trim($info['category_id'],','));
$blogCategoryModel = new BlogCategoryModel();
$category_list = $blogCategoryModel->list(['id'=>['in',$cate]],'id',['name']);
$str = '';
foreach ($category_list as $v){
$str .= $v['name'].',';
}
$info['category_name'] = trim($str,',');
$blogCategoryLogic = new BlogCategoryLogic();
$info = $blogCategoryLogic->get_category_name($info);
//获取标签名称
$blogLabelLogic = new BlogLabelLogic();
$info = $blogLabelLogic->get_label_name($info);
//写入缓存
Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
return $this->success($info);
}
... ...
... ... @@ -104,22 +104,11 @@ class Base extends Model
*/
public function read($condition,$files = ['*'])
{
//读取缓存
$cache = config('cache.user_is_cache');
if(($cache['is_cache'] == true) && isset($condition['id'])){
$info = Common::get_user_cache($this->getTable(),$condition['id']);
if(!empty($info)){
return $info;
}
}
$query = $this->formatQuery($condition);
$info = $query->select($files)->first();
if (empty($info)) {
return false;
}
if(($cache['is_cache'] == true) && isset($condition['id'])){
Common::set_user_cache($info,$this->getTable(),$condition['id']);
}
$info = $info->toArray();
return $info;
}
... ... @@ -143,13 +132,8 @@ class Base extends Model
public function edit($data,$condition){
$query = $this->formatQuery($condition);
$data['updated_at'] = date('Y-m-d H:i:s');
$rs = $query->update($data);
//更新缓存
$cache = config('cache.user_is_cache');
if(($cache['is_cache'] == true) && isset($condition['id'])) {
Common::del_user_cache($this->getTable(), $condition['id']);
}
return $rs;
return $query->update($data);
}
/**
* @name : 删除数据
... ...