Skip to content

Instantly share code, notes, and snippets.

@jjhamshaw
Created April 22, 2015 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjhamshaw/ad1659f3c97cc3347b98 to your computer and use it in GitHub Desktop.
Save jjhamshaw/ad1659f3c97cc3347b98 to your computer and use it in GitHub Desktop.
A simple System.Runtime.Caching.MemoryCache wrapper
public class AppCache : ICache
{
public object GetValue(string key)
{
MemoryCache memoryCache = MemoryCache.Default;
return memoryCache.Get(key);
}
public bool Add(string key, object value, DateTimeOffset absExpiration)
{
MemoryCache memoryCache = MemoryCache.Default;
return memoryCache.Add(key, value, absExpiration);
}
public void Delete(string key)
{
MemoryCache memoryCache = MemoryCache.Default;
if (memoryCache.Contains(key))
{
memoryCache.Remove(key);
}
}
}
public interface ICache
{
object GetValue(string key)
bool Add(string key, object value, DateTimeOffset absExpiration)
void Delete(string key)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment