internal async Task SetExpirationTimeAsync <TValue>(ScopedCacheItem <TValue> scopedCacheItem)
 {
     if (scopedCacheItem.ExpireIn.HasValue)
     {
         await ExpireByIdAsync(scopedCacheItem.Id, scopedCacheItem.ExpireIn.Value).ConfigureAwait(false);
     }
 }
 internal void SetExpirationTime <TValue>(ScopedCacheItem <TValue> scopedCacheItem)
 {
     if (scopedCacheItem.ExpireIn.HasValue)
     {
         ExpireById(scopedCacheItem.Id, scopedCacheItem.ExpireIn.Value);
     }
 }
        internal async Task <ScopedCacheItem <TValue> > GetItemAsync <TValue>(String cacheName, String key)
        {
            var id = ScopedCacheItem <TValue> .GetId(cacheName, key);

            var scopedCacheItemString = await client.Database.StringGetAsync(id).ConfigureAwait(false);

            return(convert.FromScopedRedis <TValue>(scopedCacheItemString));
        }
        internal ScopedCacheItem <TValue> GetItem <TValue>(String cacheName, String key)
        {
            var id = ScopedCacheItem <TValue> .GetId(cacheName, key);

            var scopedCacheItemString = client.Database.StringGet(id);

            return(convert.FromScopedRedis <TValue>(scopedCacheItemString));
        }
        internal Task ClearItemsAsync(String cacheName)
        {
            var keyPrefix = ScopedCacheItem <object> .GetId(cacheName, string.Empty);

            var keys = client.MasterServer.Keys(0, string.Format("*{0}*", keyPrefix), 1000, CommandFlags.None).ToArray();

            return(client.Database.KeyDeleteAsync(keys, CommandFlags.None));
        }
Exemple #6
0
 private void ResetExpirationTime <TValue>(ScopedCacheItem <TValue> cacheItem)
 {
     if (expireWithin.HasValue && useSlidingExpiration)
     {
         InnerCache.SetIfNotExists(cacheItem);
         cacheItem.ExpireIn = this.expireWithin.Value;
         InnerCache.SetExpirationTime(cacheItem);
     }
 }
 internal bool SetIfNotExists <TValue>(ScopedCacheItem <TValue> scopedCacheItem)
 {
     if (Contains(scopedCacheItem.Id))
     {
         return(false);
     }
     SetItem(scopedCacheItem);
     return(true);
 }
Exemple #8
0
        private async Task ResetExpirationTimeAsync <TValue>(ScopedCacheItem <TValue> cacheItem)
        {
            if (expireWithin.HasValue && useSlidingExpiration)
            {
                await InnerCache.SetIfNotExistsAsync(cacheItem).ConfigureAwait(false);

                cacheItem.ExpireIn = expireWithin.Value;
                await InnerCache.SetExpirationTimeAsync(cacheItem).ConfigureAwait(false);
            }
        }
        internal async Task <bool> SetIfNotExistsAsync <TValue>(ScopedCacheItem <TValue> scopedCacheItem)
        {
            if (await ContainsAsync(scopedCacheItem.Id).ConfigureAwait(false))
            {
                return(false);
            }
            await SetItemAsync(scopedCacheItem).ConfigureAwait(false);

            return(true);
        }
        internal Task SetItemAsync <TValue>(ScopedCacheItem <TValue> scopedCacheItem)
        {
            TimeSpan?expiry = null;

            if (scopedCacheItem.ExpireIn.HasValue)
            {
                expiry = scopedCacheItem.ExpireIn;

                if (expiry.Value.TotalSeconds <= 0)
                {
                    return(client.Database.KeyDeleteAsync(scopedCacheItem.Id, CommandFlags.None));
                }
            }

            return(client.Database
                   .StringSetAsync(scopedCacheItem.Id, convert.ToScopedRedis(scopedCacheItem), expiry, When.Always, CommandFlags.None));
        }
Exemple #11
0
        private ScopedCacheItem <TValue> CreateCacheItem <TValue>(string key, TValue value, DateTimeOffset valueTimestamp)
        {
            ScopedCacheItem <TValue> newItem;

            if (!expireAt.HasValue && expireWithin.HasValue)
            {
                newItem = new ScopedCacheItem <TValue>(this.Name, key, value, valueTimestamp, expireWithin.Value);
            }
            else if (expireAt.HasValue)
            {
                newItem = new ScopedCacheItem <TValue>(this.Name, key, value, valueTimestamp, expireAt.Value.Subtract(DateTime.Now));
            }
            else
            {
                newItem = new ScopedCacheItem <TValue>(this.Name, key, value, valueTimestamp);
            }

            return(newItem);
        }
        internal Task RemoveItemAsync(String cacheName, String key)
        {
            var id = ScopedCacheItem <object> .GetId(cacheName, key);

            return(client.Database.KeyDeleteAsync(id, CommandFlags.None));
        }
        internal void RemoveItem(String cacheName, String key)
        {
            var id = ScopedCacheItem <object> .GetId(cacheName, key);

            client.Database.KeyDelete(id, CommandFlags.None);
        }
        internal void ExpireItemIn <TValue>(String cacheName, String key, TimeSpan timeSpan)
        {
            var id = ScopedCacheItem <TValue> .GetId(cacheName, key);

            ExpireById(id, timeSpan);
        }