2012-03-20 59 views
0

我想了解如何重用我的Linqtotwitter結果以便在我的應用程序中重用。 一切工作正常,除非我打算速度限制非常迅速,如果我不做一種形式的緩存。我在我的應用程序中有3個查詢觸發了twitter feed。緩存Linq重用結果MVC 3

我試圖使用http://ardalis.com/introducing-the-cachedrepository-pattern的知識庫模式,但它在我頭上的方式,讓我只是說我沒有得到太多。

樣本控制器從我的代碼

[HttpGet] 
    public ActionResult PublicShouts()  
    { 

     var twitterCtx = new TwitterContext(Auth); 





     List<TweetViewModel> friendstweets = (from tweet in twitterCtx.Status 
               where tweet.Type == StatusType.User &&           
               tweet.ScreenName == "BattleShouts" && 
             //  tweet.InReplyToScreenName == "Battleshouts" && 
               tweet.IncludeEntities == true && 
               tweet.IncludeRetweets == true && 
              tweet.IncludeContributorDetails == true && 
               tweet.CreatedAt < DateTime.Now.AddDays(-30).Date 
               select new TweetViewModel 
               { 

                ImageUrl = tweet.User.ProfileImageUrl, 
                ScreenName = tweet.User.Identifier.ScreenName, 
                Tweet = tweet.Text 
               }) 
.ToList(); 

return PartialView(friendstweets); 

我也看了這個帖子How to cache data in a MVC application

我怎麼能去緩存我以備後用,所以我不打了極限Twitter的結果?

謝謝

回答

0

OutputCacheAttribute怎麼樣?

http://msdn.microsoft.com/en-us/library/system.web.mvc.outputcacheattribute.aspx

看VaryByCustom是有每個用戶單獨的緩存條目。

+0

緩存控制器的行爲,而不是重複使用的結果,我也使用它。 – 2012-03-20 20:49:13

+0

如果你想緩存'List '看看'ConcurrentDictionary' – 2012-03-20 21:14:33

+0

我可以使用類似這樣的東西http://stackoverflow.com/questions/7540257/how-to-cache-mvc3-webgrid-results-如此即排序的點擊不能?我不遵循你的服用方向。併發字典帶我穿線 – 2012-03-21 02:14:02