Exemplo n.º 1
0
        public override void Overwrite <T>(String key, T value, TimeSpan slidingExpiration)
        {
            if (_config.Readonly)
            {
                throw new InvalidOperationException();
            }
            var cacheKey = BuildCacheKey(key);
            var db       = _connection.GetDatabase();

            db.StringSet(cacheKey, NewtonsoftJsonUtil.Stringify(value));
            db.KeyExpire(cacheKey, slidingExpiration);
        }
Exemplo n.º 2
0
        public override bool TryGet <T>(String key, out T value)
        {
            var db    = _connection.GetDatabase();
            var entry = db.StringGet(BuildCacheKey(key));

            if (!entry.HasValue)
            {
                value = default(T);
                return(false);
            }
            value = NewtonsoftJsonUtil.Parse <T>(entry);
            return(true);
        }
Exemplo n.º 3
0
 public override void Overwrite <T>(String key, T value)
 {
     if (_config.Readonly)
     {
         throw new InvalidOperationException();
     }
     if (_config.MaxExpiration.HasValue)
     {
         Overwrite(key, value, _config.MaxExpiration.Value);
     }
     else
     {
         var db = _connection.GetDatabase();
         db.StringSet(BuildCacheKey(key), NewtonsoftJsonUtil.Stringify(value));
     }
 }