Ejemplo n.º 1
0
        public async Task Invoke(HttpContext context)
        {
            await _next(context); // Pass the control to the next middleware

            IList <string> news;

            if (!_cache.TryGetValue <IList <string> >("latestNews", out news))
            {
                news = _newsServices.GetLatestNews();
                var options = new MemoryCacheEntryOptions()
                {
                    SlidingExpiration  = TimeSpan.FromMinutes(5),
                    AbsoluteExpiration = DateTimeOffset.UtcNow.AddHours(1)
                };

                // The entry can be removed, is not priority
                options.Priority = CacheItemPriority.Low;

                // Never removed the entry automatically
                // We do this manually
                options.Priority = CacheItemPriority.NeverRemove;

                _cache.Set("latestNews", news, options);

                // To invalidate an entry
                _cache.Remove("latestNews");
            }

            await context.Response.WriteAsync($"\nNumber of News: {news.Count}");
        }
Ejemplo n.º 2
0
        public HomeEntity Get()
        {
            HomeEntity entity = new HomeEntity();

            entity.News        = newsServices.GetLatestNews();
            entity.Events      = eventServices.GetAllEvents();
            entity.Departments = deptServices.GetAllDepartments();
            return(entity);
        }
Ejemplo n.º 3
0
 public IEnumerable <NewsEntity> GetLatestNews()
 {
     return(newsServices.GetLatestNews());
 }