I am using linqtotwitter and I am struggling with a good way to present data without constantly paging the controller and hitting twitter for data.
With twitter if you do a hit it counts against you whether you get information or not.
This problem sorta came to my head when i had noticed my page had 2-3 hits per load which isnt good if i have a popular site. 350 requests will go fast.
How should i store my list so I hit the results not the query each time.
Outputcache helps but doesnt address my core issue.
I guess i got sorta 2 problems or 1 depending how you look at it,
II have a mvc page with multiple partial views and is working great.
What you want to do is Cache the data (in code caching, not output caching) from linqtotwitter. When a user requests data the controller should check the cache first and only pull from twitter if the cache is not there. That way, you can load up a lot of
data on the first request and not go to twitter again if you have that data.
One way to do this elegantly without maknig your controller too complicated is to the linqtotwitter code put it behind a repository class. Then you can use a cached repository pattern to save the data locally to the Cache object. http://ardalis.com/introducing-the-cachedrepository-pattern
With the cached repository pattern, your controller reads from a single interface and doesn't even know the data is cached, the caching happens at a different layer.
so basically I was doing another thing wrong in my code practice before i even get started
In this musicstore code it creates a private list method and passes it to the index controller. I would need to do the same before i even started on this pattern
public ActionResult Index()
{
// Get most popular albumsvar albums = GetTopSellingAlbums(5);
return View(albums);
}
private List<Album> GetTopSellingAlbums(int count)
{
// Group the order details by album and return// the albums with the highest countreturn storeDB.Albums
.OrderByDescending(a => a.OrderDetails.Count())
.Take(count)
.ToList();
}
mbhahn
Member
169 Points
119 Posts
Reusing controller data for multiple views
Mar 20, 2012 04:07 PM|LINK
I am using linqtotwitter and I am struggling with a good way to present data without constantly paging the controller and hitting twitter for data.
With twitter if you do a hit it counts against you whether you get information or not.
This problem sorta came to my head when i had noticed my page had 2-3 hits per load which isnt good if i have a popular site. 350 requests will go fast.
How should i store my list so I hit the results not the query each time.
Outputcache helps but doesnt address my core issue.
I guess i got sorta 2 problems or 1 depending how you look at it,
II have a mvc page with multiple partial views and is working great.
Here is a sample for query.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Reusing controller data for multiple views
Mar 20, 2012 04:14 PM|LINK
What you want to do is Cache the data (in code caching, not output caching) from linqtotwitter. When a user requests data the controller should check the cache first and only pull from twitter if the cache is not there. That way, you can load up a lot of data on the first request and not go to twitter again if you have that data.
One way to do this elegantly without maknig your controller too complicated is to the linqtotwitter code put it behind a repository class. Then you can use a cached repository pattern to save the data locally to the Cache object.
http://ardalis.com/introducing-the-cachedrepository-pattern
With the cached repository pattern, your controller reads from a single interface and doesn't even know the data is cached, the caching happens at a different layer.
Blog | Twitter : @Hattan
mbhahn
Member
169 Points
119 Posts
Re: Reusing controller data for multiple views
Mar 20, 2012 05:10 PM|LINK
so basically I was doing another thing wrong in my code practice before i even get started
In this musicstore code it creates a private list method and passes it to the index controller. I would need to do the same before i even started on this pattern