public IEnumerable <PostEntity> GetPosts(Expression <Func <PostEntity, bool> > predicate = null, params Expression <Func <PostEntity, object> >[] includes) { var posts = CacheHelper.GetItem(ApplicationKey.Posts) as IEnumerable <PostEntity>; if (posts != null) { return(posts); } posts = GetItems(predicate, includes); CacheHelper.AddItem(ApplicationKey.Posts, posts, new TimeSpan(1, 0, 0, 0)); return(posts); }
public IEnumerable <TagEntity> GetTags(Expression <Func <TagEntity, bool> > predicate = null) { var tags = CacheHelper.GetItem(ApplicationKey.Tags) as IEnumerable <TagEntity>; if (tags != null) { return(tags); } tags = GetItems(predicate); CacheHelper.AddItem(ApplicationKey.Tags, tags, new TimeSpan(1, 0, 0, 0)); return(tags); }
public async Task <IEnumerable <PostEntity> > GetPostsAsync <TKey>(Expression <Func <PostEntity, bool> > predicate, Expression <Func <PostEntity, TKey> > selector, SortOrder sortOrder, params Expression <Func <PostEntity, object> >[] includes) { var posts = CacheHelper.GetItem(ApplicationKey.Posts) as IEnumerable <PostEntity>; if (posts != null) { return(posts); } posts = await GetItemsAsync(predicate, selector, sortOrder, includes); CacheHelper.AddItem(ApplicationKey.Posts, posts, new TimeSpan(1, 0, 0, 0)); return(posts); }
// GET: Post/PostDetail public ActionResult PostDetail(int id, string slug) { var post = CacheHelper.GetItem(ApplicationKey.Post + id) as PostEntity; if (post != null) { return(View(post)); } post = _postService.GetPost(p => p.IsEnabled && p.Id == id && p.Slug == slug); if (post == null) { return(HttpNotFound()); } CacheHelper.AddItem(ApplicationKey.Post + id, post, new TimeSpan(0, 12, 0, 0)); return(View(post)); }