/// <summary> /// 更新指定项 /// </summary> /// <param name="key"></param> /// <param name="obj"></param> /// <returns></returns> public bool Set(TKey key, TValue obj, int cacheTime = 0, bool refreshCreateTime = false, int minCounter = 0) { if (!Add(key, obj, cacheTime, refreshCreateTime, minCounter)) { var cacheValue = new AgileCacheValue <TValue>(obj, cacheTime, refreshCreateTime, minCounter); var cacheKey = new AgileCacheKey <TKey>(key); cache[cacheKey] = cacheValue; } return(true); }
/// <summary> /// 加入缓存项 /// </summary> /// <param name="key"></param> /// <param name="obj"></param> /// <param name="cacheTime"></param> /// <param name="refreshCreateTime"></param> /// <param name="minCounter"></param> /// <returns></returns> public bool Add(TKey key, TValue obj, int cacheTime = 0, bool refreshCreateTime = false, int minCounter = 0) { var cacheValue = new AgileCacheValue <TValue>(obj, cacheTime, refreshCreateTime, minCounter); var cacheKey = new AgileCacheKey <TKey>(key); lock (cache) { if (!cache.ContainsKey(cacheKey)) { cache.Add(cacheKey, cacheValue); return(true); } } return(false); }