public IActionResult GetDataWithInMemoryCache() { JObject geoData; string content; ObjectCache cache = MemoryCache.Default; if (cache["VietNamMapJson"] == null) { ResponseModel response = VietNamMapCommon.LoadDataForVNMap(out geoData); if (ResponseType.Success != response.Type) { content = JsonConvert.SerializeObject(new { success = false, data = string.Empty, message = response.Message }); return(Content(content, "application/json")); } CacheItemPolicy cachePolicy = new CacheItemPolicy(); cache.Set("VietNamMapJson", geoData.ToString(Formatting.None), cachePolicy); } else { geoData = JObject.Parse(cache["VietNamMapJson"].ToString()); } content = JsonConvert.SerializeObject(new { success = true, data = geoData }); return(Content(content, "application/json")); }
public IActionResult GetDataWithSqlServerCache() { string cacheKey = "VietNamMapJson"; JObject geoData; string content; var sqlServerCacheVietNamMap = _distributedCache.Get(cacheKey); if (sqlServerCacheVietNamMap == null) { ResponseModel response = VietNamMapCommon.LoadDataForVNMap(out geoData); if (ResponseType.Success != response.Type) { content = JsonConvert.SerializeObject(new { success = false, data = string.Empty, message = response.Message }); return(Content(content, "application/json")); } _distributedCache.Set(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(geoData))); } else { geoData = JObject.Parse(Encoding.UTF8.GetString(sqlServerCacheVietNamMap)); } content = JsonConvert.SerializeObject(new { success = true, data = geoData }); return(Content(content, "application/json")); }
public IActionResult GetData() { JObject geoData; string content = ""; ResponseModel response = VietNamMapCommon.LoadDataForVNMap(out geoData); if (ResponseType.Success != response.Type) { content = JsonConvert.SerializeObject(new { success = false, data = string.Empty, message = response.Message }); return(Content(content, "application/json")); } content = JsonConvert.SerializeObject(new { success = true, data = geoData }); return(Content(content, "application/json")); }