示例#1
0
        public async Task <T> GetOrSetAsync <T>(ScopedCacheKey cacheKey, Func <Task <T> > getItemCallback) where T : class
        {
            if (_memoryCache.Get(cacheKey) is not T item)
            {
                item = await getItemCallback();

                SetItemToCache(cacheKey, item);
            }

            return(item);
        }
示例#2
0
        public T GetOrSet <T>(ScopedCacheKey cacheKey, Func <T> getItemCallback) where T : class
        {
            if (_memoryCache.Get(cacheKey) is not T item)
            {
                item = getItemCallback();

                SetItemToCache(cacheKey, item);
            }

            return(item);
        }
示例#3
0
        private void SetItemToCache <T>(ScopedCacheKey scopedCacheKey, T item)
        {
            var options = new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.Normal).SetSlidingExpiration(TimeSpan.FromSeconds(10));

            _memoryCache.Set(scopedCacheKey, item, options);
        }