/// <summary> /// 添加缓存值 当容器中不存在key值时添加 /// 当容器中存在key值修改 /// </summary> /// <param name="argKey">key值</param> /// <param name="argValue">value值</param> /// <returns></returns> public int Insert(T argKey, V argValue) { lock (_object) { if (Dic != null) { if (Dic.ContainsKey(argKey)) { Dic[argKey].Body = argValue; } else { CacheBody <V> body = new CacheBody <V>() { Body = argValue, DependencyFile = string.Empty, Expiration = DateTime.MaxValue }; Dic.Add(argKey, body); } return(1); } else { return(0); } } }
/// <summary> /// 添加缓存值 当容器中不存在key值时添加 /// </summary> /// <param name="argKey">key值</param> /// <param name="argValue">value值</param> /// <param name="expiration">过期时间</param> /// <returns></returns> public int Add(object argKey, object argValue, DateTime expiration) { lock (_object) { if (Dic != null && !Dic.ContainsKey(argKey)) { CacheBody body = new CacheBody() { Body = argValue, Expiration = expiration, DependencyFile = string.Empty }; Dic.Add(argKey, body); return(1); } return(0); } }