Reusing Linq to twitter

Mar 29, 2012 at 7:36 PM

Hi Joe,

   I apologize for not posting more often.  I am trying to think of the best way to do this scenario, getting the newer tweets without getting the old ones i just presented to the user.


Right now I have people getting a list of 100 latest tweets on a tag. I cach  the results to a cached repository.

I need to figure out a good way to put the sinceid. I dont have a problem getting that last id but I am thinking of a way to do it with the next call.

I cant put it in the first load respository or every visitor after the first will get just updated tweets.


Should i make a 2nd repository when the ajax is called it updates from the sinceid? this way i can get an accurate count of tweets if i wanted to implement a label notifier or something

Mar 31, 2012 at 1:35 AM

One approach is to keep both the SinceID and tweets in cache.  Here's how it might work:

1. If Tweets cache is empty and if SinceID cache is empty, then do a query without SinceID.

2. If Tweets cache is empty and SinceID is not empty, then do a query using SinceID.

3. If Tweets cache is not empty, return it.

I'm assuming you're using the HttpContext.Current.Cache - or just Cache in your controller. When you add the item to the cache, do an insert with a timer that evicts the cache after a specified amount of time to keep it from getting stale.  The SinceID is a separate cache entry and you should add it to the cache so that it never expires.  It's always possible that ASP.NET will evict any items from cache at any unpredictable time, which is why you need to check to see if the data is available to decide what to do.  Here's a place you might start for your research:


Mar 31, 2012 at 1:47 AM

correct! im using steve smiths cache respository class and set it to 2 minutes and im caching the controllers to be safe.

im starting to think im wasting my time not using the steaming api since i will be using a poller to get tweets.

i found some cool timer ajax stuff


Thank you.