I'm working in a system that uses a pricing list from a REST API, which we pay for every request. So, as these prices don't change very often I keep them in memory cache. My problem is that this cache is not refreshing, for them to refresh I have to recycle the application pool. Below is the function I use to get the prices:
public static List<PricingModel> GetItemPrices()
{
var cache = MemoryCache.Default;
string key = "ItemPrices";
var val = cache[key] as List<PricingModel>;
if (val == null)
{
val = new List<PricingModel>();
val = apiProxy.GetPrices();
foreach (var price in val)
{
price.Price *= 100;
}
CacheItemPolicy policy = new CacheItemPolicy();
policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1);
cache.Set(new CacheItem(key, val), policy);
}
return val;
}
Am I missing something in the cache policy to make it actually refresh? What am I doing wrong?
Thanks for any help