Exemple #1
0
        public async Task <IActionResult> Index()
        {
            var cacheEntryOptions = new MemoryCacheEntryOptions()
                                    // Keep in cache for this time, reset time if accessed.
                                    .SetSlidingExpiration(TimeSpan.FromMinutes(10));

            _cache.Set("test", "Holi", cacheEntryOptions);

            string cacheEntry = "";

            if (_cache.TryGetValue("test", out cacheEntry))
            {
                Console.WriteLine(cacheEntry);
            }

            LibrosIndexViewModel vm = new LibrosIndexViewModel();

            try
            {
                vm.Libros = await dBContext.Libros.ToListAsync();

                if (vm.Libros.Count <= 3)
                {
                    throw new Exception("No hay libros");
                }
                return(View(vm));
            }
            catch (Exception e)
            {
                vm.HayLibros = false;
                return(View(vm));
            }
        }
Exemple #2
0
        public ActionResult Index()
        {
            var model = new LibrosIndexViewModel();

            return(View(model));
        }