【问题标题】:Caching a Linq Result for Reuse MVC 3缓存 Linq 结果以重用 MVC 3
【发布时间】:2012-03-21 04:24:37
【问题描述】:

我正在尝试学习如何重用我的 Linqtotwitter 结果以便在我的应用程序中重用。 一切正常,除非如果我不进行某种形式的缓存,我将很快达到速率限制。我的应用程序中有 3 个查询访问了 twitter 提要。

我尝试在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 限制?

谢谢

【问题讨论】:

    标签: linq asp.net-mvc-3 caching twitter


    【解决方案1】:

    OutputCacheAttribute 怎么样?

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

    查看 VaryByCustom 以便为每个用户提供单独的缓存条目。

    【讨论】:

    • 缓存控制器操作而不是结果以供重用,我也在使用它。
    • 如果你想缓存List&lt;TweetViewModel&gt;看看ConcurrentDictionary
    • 我可以使用类似stackoverflow.com/questions/7540257/… 的东西吗?我没有遵循你的方向。并发字典带我去线程
    • 是的。我提到了ConcurrenctDictionary,因为您想从多个线程访问缓存的结果。
    猜你喜欢
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 2011-06-16
    • 1970-01-01
    相关资源
    最近更新 更多