Skip to content

Commit

Permalink
feat(CachePolicy): support CachePolicy in ApiClient.CallApi()
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed May 26, 2023
1 parent bd10533 commit 717004e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/PollinationSDK/Client/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ public ApiClient(String basePath = "http://localhost")
var request = PrepareRequest(
path, method, queryParams, postBody, headerParams, formParams, fileParams,
pathParams, contentType);

// set cache policy
RestClient.CachePolicy = Env.CachePolicy;
// set timeout

RestClient.Timeout = Configuration.Timeout;
// set user agent
RestClient.UserAgent = Configuration.UserAgent;
Expand Down Expand Up @@ -206,6 +208,11 @@ public ApiClient(String basePath = "http://localhost")
var request = PrepareRequest(
path, method, queryParams, postBody, headerParams, formParams, fileParams,
pathParams, contentType);
// set cache policy
RestClient.CachePolicy = Env.CachePolicy;
// set timeout
RestClient.Timeout = Configuration.Timeout;
// set user agent
RestClient.UserAgent = Configuration.UserAgent;
InterceptRequest(request);
var response = await RestClient.ExecuteTaskAsync(request, cancellationToken);
Expand Down
13 changes: 13 additions & 0 deletions src/PollinationSDK/Helper/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,18 @@ public static int HTTPTimeout
return retVal;
}
}


private static System.Net.Cache.RequestCachePolicy _cache;

public static System.Net.Cache.RequestCachePolicy CachePolicy
{
get
{
return (_cache = _cache ?? new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.Revalidate));
}
}


}
}

0 comments on commit 717004e

Please sign in to comment.