Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.Caching;
- namespace Core.Caching {
- public class MemoryRuntimeCache:ICache {
- static readonly ObjectCache _memory = System.Runtime.Caching.MemoryCache.Default;
- public int Count {
- get {
- return (int)_memory.GetCount();
- }
- }
- public object this[string key] {
- get {
- var item = _memory.GetCacheItem(key);
- if(item == null)
- return null;
- return item.Value;
- }
- set {
- _memory[key] = value;
- }
- }
- public object Add(string key,object value,System.Web.Caching.CacheDependency dependencies,DateTime absoluteExpiration,TimeSpan slidingExpiration,System.Web.Caching.CacheItemPriority priority,System.Web.Caching.CacheItemRemovedCallback onRemoveCallback) {
- _memory[key] = value;
- return value;
- }
- public object Get(string key) {
- var item = _memory.GetCacheItem(key);
- if(item == null)
- return null;
- return item.Value;
- }
- public void Insert(string key,object value) {
- _memory[key] = value;
- }
- public void Insert(string key,object value,System.Web.Caching.CacheDependency dependencies) {
- _memory[key] = value;
- }
- public void Insert(string key,object value,System.Web.Caching.CacheDependency dependencies,DateTime absoluteExpiration,TimeSpan slidingExpiration) {
- _memory[key] = value;
- }
- public void Insert(string key,object value,System.Web.Caching.CacheDependency dependencies,DateTime absoluteExpiration,TimeSpan slidingExpiration,System.Web.Caching.CacheItemUpdateCallback onUpdateCallback) {
- _memory[key] = value;
- }
- public void Insert(string key,object value,System.Web.Caching.CacheDependency dependencies,DateTime absoluteExpiration,TimeSpan slidingExpiration,System.Web.Caching.CacheItemPriority priority,System.Web.Caching.CacheItemRemovedCallback onRemoveCallback) {
- _memory[key] = value;
- }
- public object Remove(string key) {
- return _memory.Remove(key);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment