Skip to content

Instantly share code, notes, and snippets.

@valm
Created October 8, 2013 16:25
Show Gist options
  • Save valm/6887362 to your computer and use it in GitHub Desktop.
Save valm/6887362 to your computer and use it in GitHub Desktop.
Caching
public interface ICacheService
{
T Get<T>(string cacheID, Func<T> getItemCallback) where T : class;
}
public class InMemoryCache:ICacheService
{
public T Get<T>(string cacheID, Func<T> getItemCallback) where T : class
{
T item = HttpRuntime.Cache.Get(cacheID) as T;
if (item == null)
{
item = getItemCallback();
HttpRuntime.Cache.Insert(
cacheID, item, null, DateTime.Now.AddHours(1d), System.Web.Caching.Cache.NoSlidingExpiration);
}
return item;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment