Skip to content

Instantly share code, notes, and snippets.

View irobinson's full-sized avatar

Ian Robinson irobinson

View GitHub Profile
@jwcarroll
jwcarroll / CacheHelper.cs
Created November 12, 2012 17:03
Cache Helper to make using the Memory cache a little easier
public static class CacheHelper
{
private static readonly Object _locker = new object();
public static T GetCacheItem<T>(String key, Func<T> cachePopulate, TimeSpan? slidingExpiration = null, DateTime? absoluteExpiration = null)
{
if(String.IsNullOrWhiteSpace(key)) throw new ArgumentException("Invalid cache key");
if(cachePopulate == null) throw new ArgumentNullException("cachePopulate");
if(slidingExpiration == null && absoluteExpiration == null) throw new ArgumentException("Either a sliding expiration or absolute must be provided");