Last active
December 15, 2015 03:58
-
-
Save aruss/5197876 to your computer and use it in GitHub Desktop.
Cache Helper
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 static class CacheHelper | |
{ | |
public static string GetCachedResult(string key, Func<string> handle, int espiration = 86400) | |
{ | |
var cache = HttpContext.Current.Cache; | |
var response = cache.Get(key); | |
if (response == null) | |
{ | |
response = handle(); | |
cache.Add(key, response, null, DateTime.Now.AddSeconds(espiration), | |
TimeSpan.Zero, CacheItemPriority.Normal, null); | |
} | |
return response.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment