/// <summary> /// 配置文件初始 /// </summary> /// <param name="sectionName">节点名称</param> /// <param name="cacheKey">缓存Key</param> protected static void Init(string sectionName, string cacheKey) { TEntity section = ConfigHelper.GetSection <TEntity>(sectionName); if (section != null) { CachingHelper.Set(cacheKey, section); } }
/// <summary> /// 多语言资源文件初始 /// </summary> /// <param name="languages"></param> public static void LanguageResourceInit(List <CultureInfo> languages) { Assembly asm = Assembly.Load("App_GlobalResources"); foreach (var item in StringHelper.ToArray(SettingConfig.GetValue(KeyModel.Config.Setting.KeyResourceScript), new string[] { "," })) { #region 脚本资源文件处理 var itemArr = StringHelper.ToArray(item, new string[] { "|" }); if (!(itemArr != null && itemArr.Length == 2)) { continue; } Type resourceType = asm.GetType(itemArr[0]); ResourceManager resourceMgr = new ResourceManager(itemArr[0], asm); if (VerifyHelper.IsEmpty(resourceType) || VerifyHelper.IsEmpty(resourceMgr)) { continue; } foreach (var culture in languages) { string context = ScriptsHelper.GetJSONStringByList(ResourceHelper.GetList(resourceType, resourceMgr, culture), itemArr[1]); if (!VerifyHelper.IsEmpty(context)) { FileHelper.WriterFile(string.Format("{0}/{1}.{2}.js", HttpContext.Current.Server.MapPath(SettingConfig.GetValue(KeyModel.Config.Setting.KeyCulturePath, KeyModel.Config.Setting.GroupWebsite)), itemArr[1], culture), context); } } #endregion } foreach (var name in StringHelper.ToArray(SettingConfig.GetValue(KeyModel.Config.Setting.KeyResourceCache), new string[] { "," })) { #region 缓存资源文件处理 Type resourceType = asm.GetType(name); ResourceManager resourceMgr = new ResourceManager(name, asm); if (VerifyHelper.IsEmpty(resourceType) || VerifyHelper.IsEmpty(resourceMgr)) { continue; } foreach (var culture in languages) { var list = ResourceHelper.GetList(resourceType, resourceMgr, culture); if (!VerifyHelper.IsEmpty(list)) { CachingHelper.Set(string.Format("_RESOURCE_{0}_{1}", resourceType.FullName, culture), list); } } #endregion } }
/// <summary> /// 应用缓存初始 /// </summary> public static void AppCacheInit() { var quests = EngineHelper.Resolve <IQuestService>().GetAll(); var flows = EngineHelper.Resolve <IQuestFlowService>().GetAll(); quests.ForEach(item => { item.Flows = new List <QuestFlowEntity>(); var currents = flows.Where(x => x.QuestId == item.Id).ToList(); item.Flows = currents?.ToList(); }); CachingHelper.Set <List <QuestEntity> >(AppConst.CacheQuestList, quests); }
/// <summary> /// 重写基类的取配置,加入缓存机制 /// </summary> public override T Get <T>(string index = null) { var fileName = this.GetConfigFileName <T>(index); var key = "ConfigFile_" + fileName; var content = CachingHelper.Get(key); if (content != null) { return((T)content); } var value = base.Get <T>(index); CachingHelper.Set(key, value, new CacheDependency(ConfigService.GetFilePath(fileName))); return(value); }
public static void SetContainer(IContainer container) { CachingHelper <HttpRuntimeCaching> .Set(KeyModel.Cache.Container, container); }