internal void RemoveCache(CacheConfigInfo cacheConfigInfo) { lock (cacheConfigInfo) { //移除有关联关系表中的缓存 foreach (string entityName in cacheConfigInfo.RelationList) { RemoveCache(entityName); } //移除本表中的缓存 RemoveCache(cacheConfigInfo.EntityName); } }
private void InitSession(DbProvider dbProvider) { this.dbProvider = dbProvider; this.dbProvider.SetEventHandler(Decrypt); this.dbProvider.DataCache = new DataCache(); this.dbTrans = new DbTrans(dbProvider, false); #region 加载缓存配置 try { object cacheConfig = ConfigurationManager.GetSection("cacheConfig"); if (cacheConfig != null) { CacheConfigurationSection config = (CacheConfigurationSection)cacheConfig; IDictionary <string, CacheConfigInfo> configMap = new Dictionary <string, CacheConfigInfo>(); //获取缓存配制 foreach (string key in config.CacheEntities.AllKeys) { if (key.Contains(".")) { string[] splittedKey = key.Split('.'); if (splittedKey[0] == this.dbProvider.ConnectName) { int expireSeconds = CacheConfigurationSection.DEFAULT_EXPIRE_SECONDS; try { expireSeconds = int.Parse(config.CacheEntities[key].Value); } catch { } string entityName = splittedKey[1].Trim(); CacheConfigInfo cacheInfo = new CacheConfigInfo(); cacheInfo.EntityName = entityName; cacheInfo.ExpireSeconds = expireSeconds; configMap.Add(entityName, cacheInfo); } } } //检测缓存依赖关系 foreach (string key in config.CacheRelations.AllKeys) { if (key.Contains(".")) { string[] splittedKey = key.Split('.'); if (splittedKey[0] == this.dbProvider.ConnectName) { string cacheKey = config.CacheRelations[key].Value; string entityName = splittedKey[1].ToLower().Trim(); string[] relationKeys = cacheKey.Split(','); if (configMap.ContainsKey(entityName)) { CacheConfigInfo cache = configMap[entityName]; foreach (string relationKey in relationKeys) { if (!cache.RelationList.Contains(relationKey)) { cache.RelationList.Add(relationKey); } } configMap[entityName] = cache; } } } } this.dbProvider.CacheConfigSection = config; this.dbProvider.CacheConfigMap = configMap; } } catch { throw new MySoftException("CacheConfig配置加载失败!"); } #endregion }