public async Task Index()

in UnicornStore/Controllers/HomeController.cs [23:51]


        public async Task<IActionResult> Index(
            [FromServices] UnicornStoreContext dbContext,
            [FromServices] IMemoryCache cache)
        {
            // Get most popular blessings
            var cacheKey = "topselling";
            List<Blessing> blessings;
            if (!cache.TryGetValue(cacheKey, out blessings))
            {
                blessings = await GetTopSellingBlessingsAsync(dbContext, 6);

                if (blessings != null && blessings.Count > 0)
                {
                    if (_appSettings.CacheDbResults)
                    {
                        // Refresh it every 10 minutes.
                        // Let this be the last item to be removed by cache if cache GC kicks in.
                        cache.Set(
                            cacheKey,
                            blessings,
                            new MemoryCacheEntryOptions()
                            .SetAbsoluteExpiration(TimeSpan.FromMinutes(10))
                            .SetPriority(CacheItemPriority.High));
                    }
                }
            }

            return View(blessings);
        }