コード例 #1
0
ファイル: PostService.cs プロジェクト: omidnasri/MyBlog
        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);
        }
コード例 #2
0
ファイル: TagService.cs プロジェクト: omidnasri/MyBlog
        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);
        }
コード例 #3
0
ファイル: PostService.cs プロジェクト: omidnasri/MyBlog
        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);
        }
コード例 #4
0
ファイル: PostController.cs プロジェクト: omidnasri/MyBlog
        // 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));
        }