所有字典表数据统一通过RetrieveDicts缓存数据获得,避免二次数据库访问,移除不用的Web缓存数据配置项

This commit is contained in:
Argo-Lenovo 2016-12-20 13:06:54 +08:00
parent 905675b81b
commit b166e8fff0
2 changed files with 45 additions and 100 deletions

View File

@ -41,8 +41,6 @@
<add key="GroupHelper-RetrieveGroupsByRoleId" interval="600" desc="指定角色组数据缓存"/> <add key="GroupHelper-RetrieveGroupsByRoleId" interval="600" desc="指定角色组数据缓存"/>
<add key="LogHelper-RetrieveLogs" interval="600" desc="所有日志数据缓存"/> <add key="LogHelper-RetrieveLogs" interval="600" desc="所有日志数据缓存"/>
<add key="DictHelper-RetrieveDicts" interval="600" desc="所有字典数据缓存"/> <add key="DictHelper-RetrieveDicts" interval="600" desc="所有字典数据缓存"/>
<add key="DictHelper-RetrieveDictsWebSettings" interval="600" desc="网站配置数据缓存"/>
<add key="DictHelper-RetrieveDictsIconPathSettings" interval="600" desc="网站头像目录缓存"/>
<add key="DictHelper-RetrieveDictsCategory" interval="6000" desc="字典分类数据缓存" /> <add key="DictHelper-RetrieveDictsCategory" interval="6000" desc="字典分类数据缓存" />
<add key="NotificationHelper-RetrieveNotifications" interval="600" desc="通知管理数据缓存"/> <add key="NotificationHelper-RetrieveNotifications" interval="600" desc="通知管理数据缓存"/>
<add key="UserHelper-RetrieveNewUsers" interval="300" desc="新用户数据缓存" /> <add key="UserHelper-RetrieveNewUsers" interval="300" desc="新用户数据缓存" />

View File

@ -13,8 +13,6 @@ namespace Bootstrap.DataAccess
public static class DictHelper public static class DictHelper
{ {
internal const string RetrieveDictsDataKey = "DictHelper-RetrieveDicts"; internal const string RetrieveDictsDataKey = "DictHelper-RetrieveDicts";
internal const string RetrieveWebSettingsDataKey = "DictHelper-RetrieveDictsWebSettings";
internal const string RetrieveIconPathSettingsDataKey = "DictHelper-RetrieveDictsIconPathSettings";
internal const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory"; internal const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
/// <summary> /// <summary>
/// 查询所有字典信息 /// 查询所有字典信息
@ -109,70 +107,6 @@ namespace Bootstrap.DataAccess
} }
return ret; return ret;
} }
public static IEnumerable<Dict> RetrieveWebSettings()
{
return CacheManager.GetOrAdd(RetrieveWebSettingsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveWebSettingsDataKey), key =>
{
string sql = "select ID, Category, Name, Code, Define from Dicts where Category = N'网站设置' and Define = 0";
List<Dict> Dicts = new List<Dict>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
Dicts.Add(new Dict()
{
ID = (int)reader[0],
Category = (string)reader[1],
Name = (string)reader[2],
Code = (string)reader[3],
Define = (int)reader[4]
});
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return Dicts;
}, CacheSection.RetrieveDescByKey(RetrieveWebSettingsDataKey));
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebTitle()
{
var settings = DictHelper.RetrieveWebSettings();
return (settings.FirstOrDefault(d => d.Name == "网站标题") ?? new Dict() { Code = "后台管理系统" }).Code;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebFooter()
{
var settings = DictHelper.RetrieveWebSettings();
return (settings.FirstOrDefault(d => d.Name == "网站页脚") ?? new Dict() { Code = "2016 © 通用后台管理系统" }).Code;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveWebCss()
{
var data = RetrieveDicts();
return data.Where(d => d.Category == "网站样式");
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveActiveCss()
{
var data = RetrieveDicts();
return data.Where(d => d.Category == "当前样式" && !d.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase));
}
/// <summary> /// <summary>
/// 保存网站个性化设置 /// 保存网站个性化设置
/// </summary> /// </summary>
@ -203,38 +137,6 @@ namespace Bootstrap.DataAccess
return ret; return ret;
} }
/// <summary> /// <summary>
/// 获取头像路径
/// </summary>
/// <returns></returns>
public static Dict RetrieveIconFolderPath()
{
return CacheManager.GetOrAdd(RetrieveIconPathSettingsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveIconPathSettingsDataKey), key =>
{
string sql = "select ID, Category, Name, Code, Define from Dicts where Category = N'头像地址' and Name = N'头像路径' and Define = 0";
var dict = new Dict() { Code = "~/Content/images/uploader/" };
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{
if (reader.Read())
{
dict = new Dict()
{
ID = (int)reader[0],
Category = (string)reader[1],
Name = (string)reader[2],
Code = (string)reader[3],
Define = (int)reader[4]
};
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return dict;
}, CacheSection.RetrieveDescByKey(RetrieveIconPathSettingsDataKey));
}
/// <summary>
/// 获取字典分类名称 /// 获取字典分类名称
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
@ -259,5 +161,50 @@ namespace Bootstrap.DataAccess
return ret; return ret;
}, CacheSection.RetrieveDescByKey(RetrieveCategoryDataKey)); }, CacheSection.RetrieveDescByKey(RetrieveCategoryDataKey));
} }
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebTitle()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "后台管理系统" }).Code;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebFooter()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "2016 © 通用后台管理系统" }).Code;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveWebCss()
{
var data = RetrieveDicts();
return data.Where(d => d.Category == "网站样式");
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveActiveCss()
{
var data = RetrieveDicts();
return data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0 && !d.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase));
}
/// <summary>
/// 获取头像路径
/// </summary>
/// <returns></returns>
public static Dict RetrieveIconFolderPath()
{
var data = RetrieveDicts();
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new Dict() { Code = "~/Content/images/uploader/" };
}
} }
} }