Exemple #1
0
        private async Task ResetExpirationTimeAsync <TValue>(CacheContext context, CacheItem <TValue> cacheItem)
        {
            if (expireWithin.HasValue && useSlidingExpiration)
            {
                await context.SetIfNotExistsAsync(cacheItem);

                cacheItem.ExpireIn = expireWithin.Value;
                await context.SetExpirationTimeAsync(cacheItem);
            }
        }
Exemple #2
0
        private async Task <TValue> GetOrAddAsync <TValue>(
            CacheContext context, string key, TValue newValue, bool doForceOverride = false)
        {
            var newItem = CreateCacheItem(key, newValue);

            if (await context.SetIfNotExistsAsync(newItem))
            {
                return(newValue);
            }

            var prevValue = await GetCacheItemAsync <TValue>(context, key);

            if (!doForceOverride && prevValue != null && prevValue.Value is TValue)
            {
                return(prevValue.Value);
            }

            await context.SetItemAsync(newItem).ConfigureAwait(false);

            return(newValue);
        }