public static MPAPIResponse CallAPI( HttpMethod httpMethod, string path, PayloadType payloadType, JObject payload, WebHeaderCollection colHeaders, bool useCache, int requestTimeout, int retries) { string key = httpMethod.ToString() + "_" + path; MPAPIResponse response = (MPAPIResponse)null; if (useCache) { response = MPCache.GetFromCache(key); if (response != null) { response.IsFromCache = true; } } if (response == null) { response = new MPRESTClient().ExecuteRequest(httpMethod, path, payloadType, payload, colHeaders, requestTimeout, retries); if (useCache) { MPCache.AddToCache(key, response); } else { MPCache.RemoveFromCache(key); } } return(response); }
private static void TryAddToCache(bool useCache, string cacheKey, MPAPIResponse response) { if (useCache) { MPCache.AddToCache(cacheKey, response); } else { MPCache.RemoveFromCache(cacheKey); } }
private static MPAPIResponse TryGetFromCache(bool useCache, string cacheKey) { MPAPIResponse response = null; if (useCache) { response = MPCache.GetFromCache(cacheKey); if (response != null) { response.IsFromCache = true; } } return(response); }
/// <summary> /// Calls the api and returns an MPApiResponse. /// </summary> /// <returns>A MPAPIResponse object with the results.</returns> public static MPAPIResponse CallAPI( HttpMethod httpMethod, string path, PayloadType payloadType, JObject payload, bool useCache, MPRequestOptions requestOptions) { string cacheKey = httpMethod.ToString() + "_" + path; MPAPIResponse response = null; if (requestOptions == null) { requestOptions = new MPRequestOptions(); } if (useCache) { response = MPCache.GetFromCache(cacheKey); if (response != null) { response.IsFromCache = true; } } if (response == null) { response = new MPRESTClient().ExecuteRequest( httpMethod, path, payloadType, payload, requestOptions); if (useCache) { MPCache.AddToCache(cacheKey, response); } else { MPCache.RemoveFromCache(cacheKey); } } return(response); }