我正在爲cms創建一個論壇包,並正在緩存一些查詢以幫助提高性能,但我不確定緩存下面的內容是否有助於/ BTW:Cachehelper是,只是增加了從高速緩存中刪除)一個簡單的輔助類緩存Linq查詢問題
// Set cache variables
IEnumerable<ForumTopic> maintopics;
if (!CacheHelper.Get(topicCacheKey, out maintopics))
{
// Now get topics
maintopics = from t in u.ForumTopics
where t.ParentNodeId == CurrentNode.Id
orderby t.ForumTopicLastPost descending
select t;
// Add to cache
CacheHelper.Add(maintopics, topicCacheKey);
}
//End Cache
// Pass to my pager helper
var pagedResults = new PaginatedList<ForumTopic>(maintopics, p ?? 0, Convert.ToInt32(Settings.ForumTopicsPerPage));
// Now bind
rptTopicList.DataSource = pagedResults;
rptTopicList.DataBind();
不LINQ只是其列舉時執行?所以上面不會起作用嗎?作爲它唯一枚舉時,我將它傳遞給尋呼助手which.Take()的基於查詢字符串值'p'的一定數量的記錄