/// <summary> /// 构造函数 /// </summary> /// <param name="cacheName">连接字符串名称</param> /// <param name="prefixKey">缓存主键前缀</param> /// <param name="expireSeconds">缓存时间,单位:秒</param> /// <param name="cacheName">缓存关联的方法名,需要删除缓存时填写</param> /// <param name="ignoreDefaultValue">是否忽略返回值的默认值</param> public DistributedCacheAttribute(DistributedCacheName cacheName, string prefixKey, int expireSeconds = 5 * 60, bool isRemoveCache = false, bool ignoreDefaultValue = true) { this.CacheName = cacheName; this.PrefixKey = prefixKey; this.ExpireSeconds = expireSeconds; this.IsRemoveCache = isRemoveCache; this.IgnoreDefaultValue = ignoreDefaultValue; }
public IDistributedCache Create(DistributedCacheName distributedCacheName) { var connStr = this.dataConfiguration.GetDistributedCacheConnStr(distributedCacheName.ToString()); if (string.IsNullOrWhiteSpace(connStr)) { throw new ApplicationException($"未找到{distributedCacheName.ToString()}的连接配置"); } lock (objLock) { if (!cacheContainer.ContainsKey(distributedCacheName)) { cacheContainer.Add(distributedCacheName, this.CreateInstance(connStr)); } return(cacheContainer[distributedCacheName]); } }