提交 c1e8003c 编写于 作者: G gongfuxiang

缓存key统一读取

上级 d87a143d
......@@ -10,6 +10,7 @@
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\service\SystemService;
use app\service\ApiService;
use app\service\PluginsService;
use app\service\ResourcesService;
......@@ -85,7 +86,7 @@ class Plugins extends Common
}
// 插件权限校验
$power_plugins = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$this->admin['id']);
$power_plugins = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$this->admin['id']);
if(empty($power_plugins) || !array_key_exists($params['data_request']['pluginsname'], $power_plugins))
{
$msg = '无权限使用该插件';
......
......@@ -10,6 +10,7 @@
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\service\SystemService;
use app\service\ConfigService;
use app\service\GoodsService;
use app\service\SiteService;
......@@ -382,11 +383,11 @@ class Site extends Common
{
// 登录
case 'login' :
MyCache(MyConfig('shopxo.cache_user_login_left_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_user_login_left_key'), null);
// 密码找回
case 'forgetpwd' :
MyCache(MyConfig('shopxo.cache_user_forgetpwd_left_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_user_forgetpwd_left_key'), null);
break;
}
}
......
......@@ -10,6 +10,7 @@
// +----------------------------------------------------------------------
namespace app\index\controller;
use app\service\SystemService;
use app\service\OrderService;
use app\service\GoodsService;
use app\service\UserService;
......@@ -221,7 +222,7 @@ class User extends Common
MyViewAssign('home_seo_site_title', SeoService::BrowserSeoTitle('密码找回', 1));
// 左侧图片,随机其中一个
$left_data = UserService::UserEntranceLeftData(['left_key'=>'forgetpwd', 'cache_key'=>MyConfig('shopxo.cache_user_forgetpwd_left_key')]);
$left_data = UserService::UserEntranceLeftData(['left_key'=>'forgetpwd', 'cache_key'=>SystemService::CacheKey('shopxo.cache_user_forgetpwd_left_key')]);
MyViewAssign('user_forgetpwd_left_data', empty($left_data['data']) ? [] : $left_data['data'][array_rand($left_data['data'], 1)]);
return MyView();
......@@ -287,7 +288,7 @@ class User extends Common
MyViewAssign('referer_url', $this->GetrefererUrl());
// 左侧图片,随机其中一个
$left_data = UserService::UserEntranceLeftData(['left_key'=>'login', 'cache_key'=>MyConfig('shopxo.cache_user_login_left_key')]);
$left_data = UserService::UserEntranceLeftData(['left_key'=>'login', 'cache_key'=>SystemService::CacheKey('shopxo.cache_user_login_left_key')]);
MyViewAssign('user_login_left_data', empty($left_data['data']) ? [] : $left_data['data'][array_rand($left_data['data'], 1)]);
return MyView();
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\AdminService;
use app\service\AdminRoleService;
......@@ -189,9 +190,9 @@ class AdminPowerService
{
foreach($admin as $id)
{
MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$id, null);
MyCache(MyConfig('shopxo.cache_admin_power_key').$id, null);
MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$id, null);
MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$id, null);
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$id, null);
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$id, null);
}
}
}
......@@ -213,9 +214,9 @@ class AdminPowerService
$role_id = isset($admin['role_id']) ? intval($admin['role_id']) : 0;
// 读取缓存数据
$admin_left_menu = MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin_id);
$admin_power = MyCache(MyConfig('shopxo.cache_admin_power_key').$admin_id);
$admin_plugins = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin_id);
$admin_left_menu = MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin_id);
$admin_power = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin_id);
$admin_plugins = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin_id);
// 缓存没数据则从数据库重新读取
if((($role_id > 0 || $admin_id == 1) && empty($admin_left_menu)) || $is_refresh || MyEnv('app_debug'))
......@@ -309,9 +310,9 @@ class AdminPowerService
$admin_plugins = Db::name('RolePlugins')->where(['role_id'=>$role_id])->column('name', 'plugins');
}
}
MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin_id, $admin_left_menu);
MyCache(MyConfig('shopxo.cache_admin_power_key').$admin_id, $admin_power);
MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin_id, $admin_plugins);
MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin_id, $admin_left_menu);
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin_id, $admin_power);
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin_id, $admin_plugins);
}
return true;
}
......@@ -329,7 +330,7 @@ class AdminPowerService
$admin = AdminService::LoginInfo();
if(!empty($admin['id']))
{
$data = MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin['id']);
$data = MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin['id']);
}
// 后台左侧菜单钩子
......@@ -357,7 +358,7 @@ class AdminPowerService
$admin = AdminService::LoginInfo();
if(!empty($admin['id']))
{
$data = MyCache(MyConfig('shopxo.cache_admin_power_key').$admin['id']);
$data = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin['id']);
}
// 后台左侧菜单权限钩子
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\AdminPowerService;
/**
......@@ -506,9 +507,9 @@ class AdminService
if(Db::name('Admin')->where(['id'=>$admin['id']])->update($data))
{
// 清空权限缓存数据
MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin['id'], null);
MyCache(MyConfig('shopxo.cache_admin_power_key').$admin['id'], null);
MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin['id'], null);
MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin['id'], null);
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin['id'], null);
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin['id'], null);
// 权限菜单初始化
AdminPowerService::PowerMenuInit();
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\ResourcesService;
/**
......@@ -274,7 +275,7 @@ class AppCenterNavService
public static function AppCenterNav($params = [])
{
// 缓存
$key = MyConfig('shopxo.cache_app_user_center_navigation_key').APPLICATION_CLIENT_TYPE;
$key = SystemService::CacheKey('shopxo.cache_app_user_center_navigation_key').APPLICATION_CLIENT_TYPE;
$data = MyCache($key);
if(empty($data))
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\ResourcesService;
/**
......@@ -269,7 +270,7 @@ class AppHomeNavService
public static function AppHomeNav($params = [])
{
// 缓存
$key = MyConfig('shopxo.cache_app_home_navigation_key').APPLICATION_CLIENT_TYPE;
$key = SystemService::CacheKey('shopxo.cache_app_home_navigation_key').APPLICATION_CLIENT_TYPE;
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\ResourcesService;
/**
......@@ -34,7 +35,7 @@ class ArticleService
public static function HomeArticleList($params = [])
{
// 从缓存获取
$key = MyConfig('shopxo.cache_home_article_list_key');
$key = SystemService::CacheKey('shopxo.cache_home_article_list_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\ResourcesService;
/**
......@@ -34,7 +35,7 @@ class BannerService
public static function Banner($params = [])
{
// 缓存
$key = MyConfig('shopxo.cache_banner_list_key').APPLICATION_CLIENT_TYPE;
$key = SystemService::CacheKey('shopxo.cache_banner_list_key').APPLICATION_CLIENT_TYPE;
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\ResourcesService;
/**
......@@ -204,7 +205,7 @@ class ConfigService
if($success > 0)
{
// 删除所有配置的缓存数据
MyCache(MyConfig('shopxo.cache_common_my_config_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_common_my_config_key'), null);
// 所有配置信息更新
self::ConfigInit(1);
......@@ -257,7 +258,7 @@ class ConfigService
*/
public static function ConfigInit($status = 0)
{
$key = MyConfig('shopxo.cache_common_my_config_key');
$key = SystemService::CacheKey('shopxo.cache_common_my_config_key');
$data = MyCache($key);
if($data === null || $status == 1)
{
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\SystemBaseService;
use app\service\ResourcesService;
use app\service\BrandService;
......@@ -63,7 +64,7 @@ class GoodsService
public static function GoodsCategoryAll($params = [])
{
// 从缓存获取
$key = MyConfig('shopxo.cache_goods_category_key');
$key = SystemService::CacheKey('shopxo.cache_goods_category_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
......@@ -219,7 +220,7 @@ class GoodsService
public static function HomeFloorList($params = [])
{
// 缓存
$key = MyConfig('shopxo.cache_goods_floor_list_key');
$key = SystemService::CacheKey('shopxo.cache_goods_floor_list_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
......@@ -2639,7 +2640,7 @@ class GoodsService
}
// 删除大分类缓存
MyCache(MyConfig('shopxo.cache_goods_category_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_goods_category_key'), null);
$res = self::GoodsCategoryDataHandle([$data]);
return DataReturn('操作成功', 0, json_encode($res[0]));
......@@ -2681,7 +2682,7 @@ class GoodsService
if(Db::name('GoodsCategory')->where(['id'=>$ids])->delete())
{
// 删除大分类缓存
MyCache(MyConfig('shopxo.cache_goods_category_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_goods_category_key'), null);
return DataReturn('删除成功', 0);
}
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\GoodsService;
/**
......@@ -34,7 +35,7 @@ class LinkService
public static function HomeLinkList($params = [])
{
// 从缓存获取
$key = MyConfig('shopxo.cache_home_link_list_key');
$key = SystemService::CacheKey('shopxo.cache_home_link_list_key');
$data = MyCache($key);
if($data == null || MyEnv('app_debug'))
{
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\BuyService;
use app\service\MessageService;
use app\service\OrderService;
......@@ -40,8 +41,8 @@ class NavigationService
public static function Nav($params = [])
{
// 读取缓存数据
$header = MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'));
$footer = MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'));
$header = MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_header_key'));
$footer = MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_footer_key'));
// 缓存没数据则从数据库重新读取,顶部菜单
if($header === null || MyEnv('app_debug'))
......@@ -157,7 +158,7 @@ class NavigationService
}
// 缓存
MyCache(MyConfig('shopxo.cache_common_home_nav_'.$nav_type.'_key'), $data, 180);
MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_'.$nav_type.'_key'), $data, 180);
return $data;
}
......@@ -470,7 +471,7 @@ class NavigationService
public static function NacDataSave($params = [])
{
// 缓存 key
$cache_key = MyConfig('shopxo.cache_common_home_nav_'.$params['nav_type'].'_key');
$cache_key = SystemService::CacheKey('shopxo.cache_common_home_nav_'.$params['nav_type'].'_key');
// 非自定义导航数据处理
if(empty($params['name']))
......@@ -573,8 +574,8 @@ class NavigationService
Db::commit();
// 清除缓存
MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'), null);
MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_header_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_footer_key'), null);
return DataReturn('删除成功');
}
......@@ -623,8 +624,8 @@ class NavigationService
if(Db::name('Navigation')->where(['id'=>intval($params['id'])])->update([$params['field']=>intval($params['state']), 'upd_time'=>time()]))
{
// 清除缓存
MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'), null);
MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_header_key'), null);
MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_footer_key'), null);
return DataReturn('编辑成功');
}
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\PluginsService;
use app\service\ResourcesService;
use app\service\SqlConsoleService;
......@@ -64,7 +65,7 @@ class PluginsAdminService
$admin = AdminService::LoginInfo();
if(!empty($admin))
{
$res = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin['id']);
$res = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin['id']);
if(!empty($res))
{
$power_plugins = $res;
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\ResourcesService;
use app\service\PluginsAdminService;
use app\service\StoreService;
......@@ -186,7 +187,7 @@ class PluginsService
*/
public static function PluginsCacheStorage($plugins, $data)
{
return MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins, $data);
return MyCache(SystemService::CacheKey('shopxo.cache_plugins_data_key').$plugins, $data);
}
/**
......@@ -200,7 +201,7 @@ class PluginsService
*/
public static function PluginsCacheData($plugins)
{
return MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins);
return MyCache(SystemService::CacheKey('shopxo.cache_plugins_data_key').$plugins);
}
/**
......@@ -214,7 +215,7 @@ class PluginsService
*/
public static function PluginsCacheDelete($plugins)
{
MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins, null);
MyCache(SystemService::CacheKey('shopxo.cache_plugins_data_key').$plugins, null);
}
/**
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\ResourcesService;
/**
......@@ -268,7 +269,7 @@ class QuickNavService
public static function QuickNav($params = [])
{
// 缓存
$key = MyConfig('shopxo.cache_quick_navigation_key').APPLICATION_CLIENT_TYPE;
$key = SystemService::CacheKey('shopxo.cache_quick_navigation_key').APPLICATION_CLIENT_TYPE;
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
/**
* 地区服务层
......@@ -261,7 +262,7 @@ class RegionService
public static function RegionAll($params = [])
{
// 缓存
$key = MyConfig('shopxo.cache_region_all_key');
$key = SystemService::CacheKey('shopxo.cache_region_all_key');
$data = MyCache($key);
if(empty($data))
{
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\facade\Db;
use app\service\SystemService;
use app\service\GoodsService;
use app\service\BrandService;
use app\service\ResourcesService;
......@@ -380,7 +381,7 @@ class SearchService
*/
public static function SearchKeywordsList($params = [])
{
$key = MyConfig('shopxo.cache_search_keywords_key');
$key = SystemService::CacheKey('shopxo.cache_search_keywords_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
......
......@@ -139,5 +139,19 @@ class SystemService
return $value;
}
/**
* 缓存key获取
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2022-04-21
* @desc description
* @param [string] $key [缓存key]
*/
public static function CacheKey($key)
{
return MyConfig($key).'_'.SYSTEM_TYPE;
}
}
?>
\ No newline at end of file
......@@ -95,7 +95,7 @@ class UserService
self::UserLoginRecord($user_login_info['id']);
if(!empty($user_login_info['token']))
{
MyCache(MyConfig('shopxo.cache_user_info').$user_login_info['token'], $user_login_info);
MyCache(SystemService::CacheKey('shopxo.cache_user_info').$user_login_info['token'], $user_login_info);
}
}
}
......@@ -114,7 +114,7 @@ class UserService
*/
public static function UserTokenData($token)
{
$user = MyCache(MyConfig('shopxo.cache_user_info').$token);
$user = MyCache(SystemService::CacheKey('shopxo.cache_user_info').$token);
if($user !== null && isset($user['id']))
{
return $user;
......@@ -2107,7 +2107,7 @@ class UserService
$user['token'] = self::CreatedUserToken($user_id);
if(Db::name('User')->where(['id'=>$user_id])->update(['token'=>$user['token'], 'upd_time'=>time()]))
{
MyCache(MyConfig('shopxo.cache_user_info').$user['token'], $user);
MyCache(SystemService::CacheKey('shopxo.cache_user_info').$user['token'], $user);
}
// web端用户登录纪录处理
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册