public ActionResult Links(int?blogId, int count = 4, string viewName = "_Links") { var cacheKey = string.Format("bloglinks_{0}_{1}", blogId, count); var cache = cacheService.Get(cacheKey, () => { var blog = blogId.HasValue ? blogService.Find(blogId.Value) : blogService.FindAll().OrderBy(b => b.Id).FirstOrDefault(); if (blog == null) { return(null); } var today = DateTime.Now.Date; var blogPosts = blog.BlogPosts .Where(p => p.PublishDate >= today) .OrderByDescending(p => p.PublishDate) .Take(count); var model = new BlogLinksViewModels { BlogName = blog.Title }; foreach (var post in blogPosts) { model.BlogPosts.Add(post.Id, post.Title); } return(model); }, invalidateKeys: "blogs", absoluteExpiration: DateTime.Now.AddMinutes(60)); if (cache == null) { return(new EmptyResult()); } return(PartialView(viewName, cache)); }
public ActionResult Links(int? blogId, int count = 4, string viewName = "_Links") { var cacheKey = string.Format("bloglinks_{0}_{1}", blogId, count); var cache = cacheService.Get(cacheKey, () => { var blog = blogId.HasValue ? blogService.Find(blogId.Value) : blogService.FindAll().OrderBy(b => b.Id).FirstOrDefault(); if (blog == null) return null; var today = DateTime.Now.Date; var blogPosts = blog.BlogPosts .Where(p => p.PublishDate >= today) .OrderByDescending(p => p.PublishDate) .Take(count); var model = new BlogLinksViewModels {BlogName = blog.Title}; foreach (var post in blogPosts) { model.BlogPosts.Add(post.Id, post.Title); } return model; }, invalidateKeys: "blogs", absoluteExpiration: DateTime.Now.AddMinutes(60)); if (cache == null) return new EmptyResult(); return PartialView(viewName, cache); }