Caching asp.net viewdata
Posted
by Tomh
on Stack Overflow
See other posts from Stack Overflow
or by Tomh
Published on 2010-06-11T08:50:47Z
Indexed on
2010/06/11
8:52 UTC
Read the original article
Hit count: 272
asp.net-mvc
|cache
Hey guys,
I'm currently thinking about caching most of my viewdata excpt user specific data after a user logs on. I thought the simplest way was caching the ViewData object itself and adding the user specific data after it was loaded. Are there any downsides of this approach? Are there better ways?
string cacheKey = "Nieuws/show/" + id;
if (HttpRuntime.Cache[cacheKey] != null)
{
ViewData = HttpRuntime.Cache[cacheKey] as ViewDataDictionary;
}
else
{
// add stuff to view data
HttpRuntime.Cache.Insert(cacheKey, ViewData, null, DateTime.Now.AddSeconds(180), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, null);
}
© Stack Overflow or respective owner