12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Membase;
- using Enyim.Caching.Memcached;
- using System.Configuration;
- namespace Bowin.Common.Cache
- {
- public class MembaseCacheProvider : ICacheProvider
- {
- public static readonly MembaseClient Client = new MembaseClient();
- private string CacheKey_Format = ConfigurationManager.AppSettings["cacheKey"] + "_{0}";
-
- public object Add(string key, object entry, DateTime utcExpiry)
- {
- object oOutObject = entry;
- key = string.Format(CacheKey_Format, key);
- if (!Client.TryGet(key, out oOutObject))
- {
- Client.Store(StoreMode.Add, key, entry, utcExpiry);
- }
- return oOutObject;
- }
- public object Get(string key)
- {
- object oOutObject = null;
- key = string.Format(CacheKey_Format, key);
- Client.TryGet(key, out oOutObject);
- return oOutObject;
- }
- public void Remove(string key)
- {
- key = string.Format(CacheKey_Format, key);
- Client.Remove(key);
- }
- public void Set(string key, object entry, DateTime utcExpiry)
- {
- object oOutObject = entry;
- key = string.Format(CacheKey_Format, key);
- if (Client.TryGet(key, out oOutObject))
- {
- Client.Store(StoreMode.Replace, key, entry, utcExpiry);
- }
- else
- {
- Client.Store(StoreMode.Add, key, entry, utcExpiry);
- }
- }
- }
- }
|