Skip to content

Instantly share code, notes, and snippets.

@aruss
Last active December 15, 2015 03:58
Show Gist options
  • Save aruss/5197876 to your computer and use it in GitHub Desktop.
Save aruss/5197876 to your computer and use it in GitHub Desktop.
Cache Helper
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