public void Cache(string key, TValue obj, TimeOutMode mode, int timeOut) { var tmp = new ItemContainer <TValue>() { Content = obj, Mode = mode, CreationTime = DateTime.Now, AccessCounter = timeOut }; bool done; switch (mode) { case TimeOutMode.AccessCount: case TimeOutMode.Never: default: done = _Cache.StoreAsync(StoreMode.Set, key, tmp).Result; break; case TimeOutMode.LastUse: case TimeOutMode.FromCreate: done = _Cache.StoreAsync(StoreMode.Set, key, tmp, new TimeSpan(00, 00, timeOut)).Result; break; } }
public virtual void Cache(TKey key, TVal obj, TimeOutMode mode, int timeOut) { if (timeOut < 0) { throw new ArgumentException($"TimeOut is a Posetive number!\r\nValue is {timeOut}"); } _Cache.AddOrUpdate(key, k => new ItemContainer <TVal> { AccessCounter = timeOut, Content = obj, CreationTime = DateTime.UtcNow, Mode = mode }, (k, v) => { v.AccessCounter = timeOut; v.Mode = mode; v.Content = obj; return(v); }); }
public void Cache(string key, string subkey, TValue obj, TimeOutMode mode, int timeOut) { Cache(joinKeis(key, subkey), obj, mode, timeOut); }
//TODO Set redis builting expier private void Store(string key, string subkey, TVal obj, TimeOutMode mode = TimeOutMode.Never, int timeOut = 0) { _Cache.ScriptEvaluate(_LuaCacheSub, new { key = (RedisKey)key, subkey = (RedisKey)subkey, value = Serialize(obj), mode = (int)mode, timer = timeOut, timerkey = GetTimerKey(key, subkey), creation = DateTime.UtcNow.Subtract(_BaseDate).TotalSeconds }, CommandFlags.FireAndForget); }