Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (21 sloc) 698 Bytes
using System;
namespace InMemoryCachingStrategies.Strategy
{
internal class BasicCacheStrategy : BaseStrategy, ICacheStrategy
{
public BasicCacheStrategy(InMemoryCache cache=null) : base(cache ?? new InMemoryCache())
{
}
public T Get<T>(string key, Func<T> fetchItemFunc, int durationInSec, params string[] tokens)
{
var cacheKey = this.CreateKey(key, tokens);
var item = this.Cache.Get<T>(cacheKey);
if (this.IsDefault(item))
{
item = fetchItemFunc();
this.Cache.Set(cacheKey, item, durationInSec, false);
}
return item;
}
}
}
You can’t perform that action at this time.