using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Text;

namespace Nirvana.Common
{
    public class Caches : ICaches
    {
        private static  MemoryCache cache = MyCache.get;

        public T GetCache<T>(string cacheKey) where T : class
        {
            if (cache.Get<T>(cacheKey) != null)
            {
                return cache.Get<T>(cacheKey);
            }
            return default(T);
        }
        public void WriteCache<T>(T value, string cacheKey) where T : class
        {
            cache.Set<T>(cacheKey, value, DateTime.Now.AddMinutes(10));
        }
        public void WriteCache<T>(T value, string cacheKey, DateTime expireTime) where T : class
        {
            cache.Set<T>(cacheKey, value, expireTime);
        }
        public void RemoveCache(string cacheKey)
        {
            cache.Remove(cacheKey);
        }
    }
}
