[feat] Add Response caching

This commit is contained in:
Yankai
2023-02-07 17:35:54 +00:00
committed by GitHub
parent 00b89daa23
commit 66587ee0d1
15 changed files with 879 additions and 5 deletions
+17 -1
View File
@@ -7,6 +7,7 @@ using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Octokit.Caching;
using Octokit.Internal;
namespace Octokit
@@ -23,7 +24,7 @@ namespace Octokit
readonly Authenticator _authenticator;
readonly JsonHttpPipeline _jsonPipeline;
readonly IHttpClient _httpClient;
internal IHttpClient _httpClient;
/// <summary>
/// Creates a new connection instance used to make requests of the GitHub API.
@@ -650,6 +651,21 @@ namespace Octokit
}
}
/// <summary>
/// Sets response cache used by the connection.
/// </summary>
/// <remarks>
/// Setting this property will wrap existing <see cref="IHttpClient"/> in <see cref="CachingHttpClient"/>.
/// </remarks>
public IResponseCache ResponseCache
{
set
{
Ensure.ArgumentNotNull(value, nameof(value));
_httpClient = new CachingHttpClient(_httpClient, value);
}
}
async Task<IApiResponse<string>> GetHtml(IRequest request)
{
request.Headers.Add("Accept", AcceptHeaders.StableVersionHtml);