using System.Runtime.Caching;
using iiie.CacheControl.DBO;

namespace iiie.CacheControl.Business.OutputCache
{
    public class MemoryOutputCache : IOutputCache
    {
        private static readonly MemoryCache Cache = MemoryCache.Default;

        public override CacheDbo Get(string key)
        {
            return Cache.Get(key) as CacheDbo;
        }

        public override void Remove(string key)
        {
            lock (Cache)
            {
                Cache.Remove(key);
            }
        }

        public override bool Contains(string key)
        {
            return Cache.Contains(key);
        }

        public override void Add(string key, CacheDbo o)
        {
            lock (Cache)
            {
                Cache.Add(key, o, new CacheItemPolicy());
            }
        }
    }
}
