0

I am trying to learn how to reuse my Linqtotwitter result for reuse in my application. Everything works fine except I am going to hit the ratelimit very quickly if I dont do a form of caching. I have 3 queries in my application that hits the twitter feed.

I tried to use the respository pattern at http://ardalis.com/introducing-the-cachedrepository-pattern but its way over my head and lets just say i didnt get far.

A sample controller from my code

    [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);

I have also looked at this post How to cache data in a MVC application

How can I go about caching my results for later reuse so I dont hit the twitter limit?

Thank you

Community
  • 1
  • 1
Michael Hahn
  • 143
  • 1
  • 5
  • 12

1 Answers1

0

How about OutputCacheAttribute?

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

Look at VaryByCustom to have separate cache entry for each user.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
  • that caches the controller action and not the result for reuse, i am using that as well. – Michael Hahn Mar 20 '12 at 20:49
  • If you want to cache `List` take a look at `ConcurrentDictionary` – Jakub Konecki Mar 20 '12 at 21:14
  • Could i use something like this http://stackoverflow.com/questions/7540257/how-to-cache-mvc3-webgrid-results-so-that-col-sort-click-doesnt ? I am not following the direction your taking. concurrent dictionary takes me to threading – Michael Hahn Mar 21 '12 at 02:14
  • Yes. I've mentioned `ConcurrenctDictionary` cause you want to access your cached result from multiple threads. – Jakub Konecki Mar 21 '12 at 11:11