Created
October 8, 2013 16:25
-
-
Save valm/6887362 to your computer and use it in GitHub Desktop.
Caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ICacheService | |
{ | |
T Get<T>(string cacheID, Func<T> getItemCallback) where T : class; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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