示例#1
0
 public void Add <T>(Key key, T item, MemoryCacheOptions options = null)
     where T : class
 {
     if (options == null)
     {
         options = MemoryCacheOptions.Default();
     }
     items[key] = new MemoryCacheItem(options, item);
 }
示例#2
0
        public T Get <T>(Key key)
            where T : class
        {
            if (!Exist(key))
            {
                return(default(T));
            }
            MemoryCacheItem item = items[key];

            if (item.IsExpired)
            {
                return(default(T));
            }
            var result = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(Newtonsoft.Json.JsonConvert.SerializeObject(item.Item));

            return(result);
        }