Context: .Net 3.5, C#
I\'d like to have caching mechanism in my Console application.
Instead of re-inventing the wheel, I\'d like to use System.Web.Caching.Cache>
Try
public class AspnetDataCache : IDataCache
{
private readonly Cache _cache;
public AspnetDataCache(Cache cache)
{
_cache = cache;
}
public AspnetDataCache()
: this(HttpRuntime.Cache)
{
}
public void Put(string key, object obj, TimeSpan expireNext)
{
if (key == null || obj == null)
return;
_cache.Insert(key, obj, null, DateTime.Now.Add(expireNext), TimeSpan.Zero);
}
public object Get(string key)
{
return _cache.Get(key);
}