I have a single controller and I want the data from my datacontext class that is pulling twitter data copied into 2 views
But i cant afford to do 2 actions where it hits the datacontext to perform 2 queries.
if I added a 2nd view to the controller i would have the problem above
my datacontext performs a querry to a list I was thinking something along the lines below where i take the one object and point it to another but that isnt good. I am also not sure if this is a c# question more then a mvc so i appologize.
var tweetShouts = newTweetMentions(auth);
var mentionTweets = tweetShouts.GetMentions();
// var Ticker = tweetShouts.GetMentions();return PartialView(mentionTweets);// && PartialView(Ticker);
Pull the data once and cache it. In the second action check the cache first, if it's there then no need to hit twitter and just use local data. If it's not pull the data from twitter and place it in the cache. You will have to tweak the expiration to make
sure you get fresh data at regular intervals.
i marked the base class virtual and no errors im gonna see if it works not sure if i am passing it in correctly or not.
Error Error 3 'myMvcTwitterSearch.DataContext.TweetMentions' does not contain a constructor that takes 0 arguments C:\Users\Mike\documents\visual studio 2010\Projects\myMvcTwitterSearch\myMvcTwitterSearch\DataContext\MentionCacheLayer.cs 12
18 myMvcTwitterSearch
i added this
public MentionCacheLayer() : base (auth)
{
// _auth = _auth;
}
but i cant get mybase auth to work since the base class had that
mbhahn
Member
169 Points
119 Posts
Single controller 2 views
Mar 23, 2012 04:40 PM|LINK
I have a single controller and I want the data from my datacontext class that is pulling twitter data copied into 2 views
But i cant afford to do 2 actions where it hits the datacontext to perform 2 queries.
if I added a 2nd view to the controller i would have the problem above
my datacontext performs a querry to a list I was thinking something along the lines below where i take the one object and point it to another but that isnt good. I am also not sure if this is a c# question more then a mvc so i appologize.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Single controller 2 views
Mar 23, 2012 05:06 PM|LINK
Pull the data once and cache it. In the second action check the cache first, if it's there then no need to hit twitter and just use local data. If it's not pull the data from twitter and place it in the cache. You will have to tweak the expiration to make sure you get fresh data at regular intervals.
Blog | Twitter : @Hattan
mbhahn
Member
169 Points
119 Posts
Re: Single controller 2 views
Mar 23, 2012 05:23 PM|LINK
So i need to build a 3rd layer that calls my datacontext that performs the query and caches
so my view can call the cache layer and i can use it anywhere i want to?
Do you recommend any simple solutions
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Single controller 2 views
Mar 23, 2012 05:26 PM|LINK
Your view wouldn't call the cache layer, the controller action method would before dispatching the data to the view.
The easiest thing would be to wrap your data context in a repository and implement something like that cached repository pattern
http://ardalis.com/introducing-the-cachedrepository-pattern
Blog | Twitter : @Hattan
mbhahn
Member
169 Points
119 Posts
Re: Single controller 2 views
Mar 23, 2012 05:52 PM|LINK
yea i seen that example i am not doing IoC for this 1 page app and i tried with unity i got lost when i had to put my query together
This is my class
{{Debug.Print("CachedAlbumRepository:GetTopSellingAlbums");var result = HttpRuntime.Cache[cacheKey] as List<Album>;{lock (CacheLockObject){result = HttpRuntime.Cache[cacheKey] as List<Album>;{result = base.GetTopSellingAlbums(count).ToList();HttpRuntime.Cache.Insert(cacheKey, result, null,return result;{{Debug.Print("CachedAlbumRepository:GetTopSellingAlbums");var result = HttpRuntime.Cache[cacheKey] as List<TweetViewModel>;{lock (CacheLockObject){result = HttpRuntime.Cache[cacheKey] as List<TweetViewModel>;{result = base.Tweetmentions.ToList();HttpRuntime.Cache.Insert(cacheKey, result, null,return result;CodeHobo
All-Star
18647 Points
2647 Posts
Re: Single controller 2 views
Mar 23, 2012 06:01 PM|LINK
You don't need to use and IoC container , but you do need to inject the dependencies. You can do that manually though through overloaded constructors.
The class look good, I would just remove the debug and change the key to be a plain string.
Blog | Twitter : @Hattan
mbhahn
Member
169 Points
119 Posts
Re: Single controller 2 views
Mar 23, 2012 07:25 PM|LINK
Im failing at something miserably, while i am inheriting the class I am not doing something fundamentally correct
plus the override and base isnt working/wiring together
mbhahn
Member
169 Points
119 Posts
Re: Single controller 2 views
Mar 23, 2012 07:29 PM|LINK
i marked the base class virtual and no errors im gonna see if it works not sure if i am passing it in correctly or not.
Error Error 3 'myMvcTwitterSearch.DataContext.TweetMentions' does not contain a constructor that takes 0 arguments C:\Users\Mike\documents\visual studio 2010\Projects\myMvcTwitterSearch\myMvcTwitterSearch\DataContext\MentionCacheLayer.cs 12 18 myMvcTwitterSearch
i added this