Created
March 8, 2016 02:45
-
-
Save shawnweisfeld/c867212b24f3d2fe7143 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using System.Web; | |
namespace BrewSite.Util | |
{ | |
public static class HttpApplicationStateBaseExtension | |
{ | |
public static async Task<T> CacheAside<T>(this HttpApplicationStateBase app, string key, double ttl, Func<Task<T>> exec) | |
where T : class, ICache | |
{ | |
T tmp = app[key] as T; | |
if (tmp == null || DateTime.Now > tmp.CachedAt.AddMinutes(ttl)) | |
{ | |
tmp = await exec.Invoke(); | |
app[key] = tmp; | |
} | |
return tmp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment