插件缓存数据优化

This commit is contained in:
Devil 2020-12-23 20:15:48 +08:00
parent 4a0615e637
commit 129ce0817f
2 changed files with 56 additions and 9 deletions

View File

@ -11,6 +11,7 @@
namespace app\service;
use think\Db;
use app\service\PluginsService;
use app\service\ResourcesService;
use app\service\SqlconsoleService;
@ -108,8 +109,10 @@ class PluginsAdminService
$config = self::GetPluginsConfig($params['id']);;
if($config !== false)
{
$cache = PluginsService::PluginsCacheData($params['id']);
$data = [
'plugins' => $params['id'],
'data' => empty($cache) ? '' : json_encode($cache),
'is_enable' => 0,
'add_time' => time(),
];
@ -379,9 +382,13 @@ class PluginsAdminService
// 是否需要删除应用数据,sql运行
$is_delete_static = (isset($params['value']) && $params['value'] == 1);
// 执行卸载sql
// 删除数据
if($is_delete_static === true)
{
// 删除缓存
PluginsService::PluginsCacheDelete($params['plugins']);
// 执行卸载sql
$uninstall_sql = APP_PATH.'plugins'.DS.$params['id'].DS.'uninstall.sql';
if(file_exists($uninstall_sql))
{
@ -394,6 +401,7 @@ class PluginsAdminService
// 删除应用文件
self::PluginsResourcesDelete($params['id'], $is_delete_static);
return DataReturn('删除成功');
}
return $ret;

View File

@ -36,12 +36,7 @@ class PluginsService
public static function PluginsData($plugins, $attachment_field = [], $is_cache = true)
{
// 从缓存获取数据
$data = [];
$key = config('shopxo.cache_plugins_data_key').$plugins;
if($is_cache === true)
{
$data = cache($key);
}
$data = ($is_cache === true) ? self::PluginsCacheData($plugins) : [];
// 数据不存在则从数据库读取
if(empty($data))
@ -91,7 +86,7 @@ class PluginsService
}
// 存储缓存
cache($key, $data);
self::PluginsCacheStorage($plugins, $data);
}
}
return DataReturn('处理成功', 0, $data);
@ -149,13 +144,57 @@ class PluginsService
if(Db::name('Plugins')->where(['plugins'=>$params['plugins']])->update(['data'=>json_encode($params['data']), 'upd_time'=>time()]))
{
// 删除缓存
cache(config('shopxo.cache_plugins_data_key').$params['plugins'], null);
self::PluginsCacheDelete($params['plugins']);
return DataReturn('操作成功');
}
return DataReturn('操作失败', -100);
}
/**
* 应用缓存c存储
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-12-23
* @desc description
* @param [string] $plugins [应用标记]
* @param [mixed] $data [应用数据]
*/
public static function PluginsCacheStorage($plugins, $data)
{
return cache(config('shopxo.cache_plugins_data_key').$plugins, $data);
}
/**
* 应用缓存获取
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-12-23
* @desc description
* @param [string] $plugins [应用标记]
*/
public static function PluginsCacheData($plugins)
{
$data = cache(config('shopxo.cache_plugins_data_key').$plugins);
return empty($data) ? '' : $data;
}
/**
* 应用缓存删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-12-23
* @desc description
* @param [string] $plugins [应用标记]
*/
public static function PluginsCacheDelete($plugins)
{
cache(config('shopxo.cache_plugins_data_key').$plugins, null);
}
/**
* 根据应用标记获取指定字段数据
* @author Devil