Skip to content

Instantly share code, notes, and snippets.

@shawnweisfeld
Created March 8, 2016 02:45
Show Gist options
  • Save shawnweisfeld/c867212b24f3d2fe7143 to your computer and use it in GitHub Desktop.
Save shawnweisfeld/c867212b24f3d2fe7143 to your computer and use it in GitHub Desktop.
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