Esempio n. 1
0
 /// <summary>
 /// Set
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="timeOut"></param>
 public void Set(string key, T value, TimeSpan timeOut)
 {
     _dic[key] = new MemoryCacheItem <T>()
     {
         Key = key, Value = value, Expired = DateTimeHelper.Now.AddSeconds(timeOut.TotalSeconds)
     };
     OnChanged?.Invoke(this, true, value);
 }
Esempio n. 2
0
        /// <summary>
        /// Set
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="timeOut"></param>
        public void Set(string key, T value, TimeSpan timeOut)
        {
            var mc = new MemoryCacheItem <T>()
            {
                Key = key, Value = value, Expired = DateTimeHelper.Now.AddSeconds(timeOut.TotalSeconds)
            };

            _dic.AddOrUpdate(key, mc, (k, v) => { return(mc); });
            OnChanged?.Invoke(true, value);
        }
Esempio n. 3
0
 /// <summary>
 /// Set
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="timeOut"></param>
 public void Set(string key, T value, TimeSpan timeOut)
 {
     _dic[key] = new MemoryCacheItem <T>()
     {
         Key = key, Value = value, Expired = DateTimeHelper.Now.AddSeconds(timeOut.TotalSeconds)
     };
     OnChanged?.Invoke(this, true, value);
     //_dic.AddOrUpdate(key, (k) =>
     //{
     //    OnChanged?.Invoke(this, true, value);
     //    return new MemoryCacheItem<T>() { Key = key, Value = value, Expired = DateTimeHelper.Now.AddSeconds(timeOut.TotalSeconds) };
     //}, (k, v) => { return mc; });
 }