public static List <AgilityContentItem> GetPosts(IAgilityContentRepository <AgilityContentItem> postsRepo, int authorID, string postsIDs, string categoriesIDs, string tagsIDs, string appendFilter, string sort, int take, int skip, out int totalCount) { string cacheKey = string.Format("Agility.Components.Blog.GetPosts_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}", postsRepo.ContentReferenceName, postsIDs, authorID, categoriesIDs, tagsIDs, appendFilter, sort, take, skip); PostsResult postsResult = AgilityDependencyCache.Select(cacheKey) as PostsResult; if (postsResult != null) { totalCount = postsResult.TotalCount; return(postsResult.Posts); } lock (_getPostsCacheLock) { if (postsResult != null) { totalCount = postsResult.TotalCount; return(postsResult.Posts); } StringBuilder sbFilter = new StringBuilder(); var posts = new List <AgilityContentItem>(); if (authorID > 0) { sbFilter.AppendFormat("AuthorID = {0}", authorID); } if (!string.IsNullOrEmpty(postsIDs)) { if (sbFilter.Length > 0) { sbFilter.Append(" AND "); } sbFilter.AppendFormat("ContentID in ({0})", postsIDs); } if (!string.IsNullOrEmpty(categoriesIDs)) { if (sbFilter.Length > 0) { sbFilter.Append(" AND "); } sbFilter.Append(BlogUtils.GetSqlContainsStatement("CategoriesIDs", categoriesIDs, ',')); } if (!string.IsNullOrEmpty(tagsIDs)) { if (sbFilter.Length > 0) { sbFilter.Append(" AND "); } sbFilter.Append(BlogUtils.GetSqlContainsStatement("BlogTagsIDs", tagsIDs, ',')); } if (!string.IsNullOrEmpty(appendFilter)) { if (sbFilter.Length > 0) { sbFilter.Append(" AND "); } sbFilter.Append(appendFilter); } string rowFilter = sbFilter.ToString(); posts = postsRepo.Items(rowFilter, sort, take, skip, out totalCount); postsResult = new PostsResult(); postsResult.TotalCount = totalCount; postsResult.Posts = posts; //cache it, but clear cache when the Blog Post list is changed AgilityDependencyCache.Insert(cacheKey, postsResult, new List <string> { postsRepo.ContentReferenceName }, DateTime.Now.AddHours(1)); return(postsResult.Posts); } }