예제 #1
0
        public bool Save <T>(T obj, string id, TimeSpan expiresIn)
        {
            if (obj == null)
            {
                return(false);
            }
            var listKey = IdentityMap.CreateKey(id);

            return(CacheSet(listKey, obj, DateTime.Now.Add(expiresIn)));
        }
예제 #2
0
        public bool SaveAll <T>(ICollection <T> list, TimeSpan expiresIn, bool expireTimeAsParameter = false)
        {
            string listKey = IdentityMap.CreateKey <T>();

            if (expireTimeAsParameter)
            {
                return(CacheSet(listKey, list, expiresIn));
            }
            return(CacheSet(listKey, list));
        }
예제 #3
0
        public T Get <T>(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(default(T));
            }

            string key = IdentityMap.CreateKey(id);

            CacheEntry cacheEntry = (CacheEntry)_memoryCache.Get(key);

            if (cacheEntry != null)
            {
                return((T)cacheEntry.Value);
            }

            return(default(T));
        }