Example #1
0
        private async Task <List <Permission> > GetListInCacheInternalAsync()
        {
            var list = await _cache.GetJsonAsync <List <Permission> >(ListCacheKey);

            if (list == null)
            {
                list = await _manager.GetListAsync();

                await _cache.SetJsonAsync(ListCacheKey, list);
            }
            return(list);

            /*
             * if (!_cache.TryGetValue(PermissionListCacheKey, out List<Permission> permissions))
             * {
             *  // Key not in cache, so get data.
             *  permissions = await _manager.GetListAsync();
             *
             *  // Set cache options.
             *  var cacheEntryOptions = new MemoryCacheEntryOptions()
             *      // Keep in cache for this time, reset time if accessed.
             *      .SetSlidingExpiration(TimeSpan.FromDays(30));
             *
             *  // Save data in cache.
             *  _cache.Set(PermissionListCacheKey, permissions, cacheEntryOptions);
             * }
             *
             * return permissions;
             */
        }