Created
April 22, 2015 02:11
-
-
Save jjhamshaw/ad1659f3c97cc3347b98 to your computer and use it in GitHub Desktop.
A simple System.Runtime.Caching.MemoryCache wrapper
This file contains hidden or 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
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