示例#1
0
 public static string ToJson(this oCacheResult rs)
 {
     if (rs == null)
     {
         return("{}");
     }
     return(JsonConvert.SerializeObject(rs));
 }
示例#2
0
        public string updateReplyCacheKey(UPDATE_TYPE type, oCacheModel cacheModel, string valKey, string jsonObject)
        {
            string       key   = Guid.NewGuid().ToString();
            oCacheResult rs    = Update(type, cacheModel, valKey, jsonObject);
            ObjectCache  cache = MemoryCache.Default;

            cache.Set(key, rs, new CacheItemPolicy());
            return(key);
        }
示例#3
0
        public string getAllJsonReplyCacheKey()
        {
            string       key   = Guid.NewGuid().ToString();
            oCacheResult rs    = getAllJson();
            ObjectCache  cache = MemoryCache.Default;

            cache.Set(key, rs, new CacheItemPolicy());
            return(key);
        }
示例#4
0
        public static bool clearCacheIfExist(this oCacheResult rs)
        {
            if (rs == null || rs.Request == null || string.IsNullOrWhiteSpace(rs.Request.RequestId))
            {
                return(true);
            }

            ObjectCache cache = MemoryCache.Default;

            if (cache.Contains(rs.Request.RequestId))
            {
                cache.Remove(rs.Request.RequestId);
            }

            return(false);
        }
示例#5
0
        public string searchDynamicReplyCacheKey(oCacheRequest request)
        {
            string key = Guid.NewGuid().ToString();

            if (string.IsNullOrWhiteSpace(request.RequestId))
            {
                request.RequestId = key;
            }
            else
            {
                key = request.RequestId;
            }
            oCacheResult rs    = SearchDynamic(request);
            ObjectCache  cache = MemoryCache.Default;

            cache.Set(key, rs, new CacheItemPolicy());
            return(key);
        }
示例#6
0
        public string insertItemReplyCacheKey(string jsonItem)
        {
            string       key = Guid.NewGuid().ToString();
            oCacheResult rs  = null;

            T item = default(T);

            try
            {
                item = JsonConvert.DeserializeObject <T>(jsonItem);
                rs   = insertItem(item);
            }
            catch (Exception ex)
            {
                rs = new oCacheResult().ToFailConvertJson(ex.Message);
            }

            ObjectCache cache = MemoryCache.Default;

            cache.Set(key, rs, new CacheItemPolicy());
            return(key);
        }