Tuesday 31 January 2012

MemcacheProvider For C#


using System;
using Enyim.Caching;
using Enyim.Caching.Memcached;

namespace CafeX.Core.Provider
{
    public class MemcacheProvider
    {
        private static MemcachedClient _instant;
        public static MemcachedClient Instant
        {
            get { return _instant ?? (_instant = new MemcachedClient()); }
        }

        public static object Get(string key)
        {
            return Instant.Get(key);
        }

        public static void Add(string key, object value)
        {
           Instant.Store(StoreMode.Add, key, value);
        }

        public static void AddWithTimeOut(string key, object value, int timeout)
        {
            Instant.Store(StoreMode.Add, key, value, DateTime.Now.AddMinutes(timeout));
        }

        public static void Update(string key, object value)
        {
            Instant.Store(StoreMode.Set, key, value);
        }

        public static void UpdateWithTimeOut(string key, object value, int timeout)
        {
            Instant.Store(StoreMode.Set, key, value, DateTime.Now.AddMinutes(timeout));
        }

        public static void Remove(string key)
        {
            Instant.Remove(key);
        }
    }
}

No comments:

Post a Comment