I have an MVC 3 site that uses cached in memory objects.
when the site first gets hit, it takes around a minute to build the cache, once built its very fast for everyone then on.
when im developing, ive had to reduce the number of cached objects as everytime i recomple my project it drops the cache and has to rebuild it.
Is there a way i can set Visual studio so it keeps the in memory cache when i recomple ?
here is some of my code i use for caching....
/// <summary>
/// Method to get all the prices
/// </summary>
public static List<DB2011_PriceRange> AllPrices
{
get
{
lock(_PriceLock)
{
if (HttpRuntime.Cache["Prices"] != null)
{
return (List<DB2011_PriceRange>)HttpRuntime.Cache["Prices"];
}
else
{
PopulatePrices();
return (List<DB2011_PriceRange>)HttpRuntime.Cache["Prices"];
}
}
}
}
/// <summary>
/// Poplate the Cache containing the prices
/// </summary>
private static void PopulatePrices()
{
// clear the cache and the list object
ClearCacheAndList("Trims", ref ListAllPrices);
using(var DB = DataContext.Get_DataContext)
{
ListAllPrices = (from p in DB.DB2011_PriceRange
select p).ToList();
}
// add the list object to the Cache
HttpRuntime.Cache.Add("Prices", ListAllPrices, null, DateTime.Now.AddHours(24), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
}
any help is always appricaiated
Truegilly