Skip to content

Instantly share code, notes, and snippets.

@SpeedOfSpin
Created December 5, 2013 15:21
Show Gist options
  • Save SpeedOfSpin/7807338 to your computer and use it in GitHub Desktop.
Save SpeedOfSpin/7807338 to your computer and use it in GitHub Desktop.
Simple wrapper for HTTP cache object.
public class InMemoryCache : ICacheService
{
public T Get<T>(string cacheID, TimeSpan duration, Func<T> getItemCallback) where T : class
{
T item = HttpRuntime.Cache.Get(cacheID) as T;
if (item == null)
{
item = getItemCallback();
HttpContext.Current.Cache.Insert(cacheID, item, null, System.Web.Caching.Cache.NoAbsoluteExpiration, duration);
}
return item;
}
}
interface ICacheService
{
T Get<T>(string cacheID, TimeSpan duration, Func<T> getItemCallback) where T : class;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment