Skip to content

Commit 4b48ff3

Browse files
committed
Rename HttpCache->GetAsync to GetResponseAsync
1 parent c3a0d96 commit 4b48ff3

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ It supports file based caching of responses based on the HTTP/1.1 caching header
1313
- Pluggable caching for `HttpClient`
1414
- Customizable cache key computation (supports both shared and private caching)
1515
- Extensible cache entry and cache handler interfaces (defaults to file based caching)
16-
- Easy integration with dependency injection
1716

1817
## Getting Started
1918

src/HttpClient.Cache/CacheHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CancellationToken cancellationToken
1919

2020
if (CanServeFromCache(request))
2121
{
22-
var result = await cache.GetWithVariationAsync(request, cancellationToken);
22+
var result = await cache.GetResponseWithVariationAsync(request, cancellationToken);
2323
if (result is not null)
2424
{
2525
foundResponse = result.Response;

src/HttpClient.Cache/Files/FileCache.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ TimeProvider timeProvider
8282
);
8383
}
8484

85-
public async ValueTask<HttpResponseMessage?> GetAsync(
85+
public async ValueTask<HttpResponseMessage?> GetResponseAsync(
8686
HttpRequestMessage request,
8787
CancellationToken cancellationToken = default
8888
)
8989
{
90-
var response = await GetWithVariationAsync(request);
90+
var response = await GetResponseWithVariationAsync(request);
9191
return response?.Response;
9292
}
9393

94-
public async ValueTask<ResponseWithVariation?> GetWithVariationAsync(
94+
public async ValueTask<ResponseWithVariation?> GetResponseWithVariationAsync(
9595
HttpRequestMessage request,
9696
CancellationToken cancellationToken = default
9797
)
@@ -173,7 +173,7 @@ TimeProvider timeProvider
173173
return null;
174174
}
175175

176-
public async Task<HttpResponseMessage?> SetResponseAsync(
176+
public async ValueTask<HttpResponseMessage?> SetResponseAsync(
177177
HttpResponseMessage response,
178178
CancellationToken cancellationToken = default
179179
)

src/HttpClient.Cache/IHttpCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IHttpCache : IAsyncDisposable, IDisposable
1010
/// </summary>
1111
/// <param name="request">The request</param>
1212
/// <returns>The cached response, or <see langword="null"/> if the response was not found</returns>
13-
ValueTask<HttpResponseMessage?> GetAsync(
13+
ValueTask<HttpResponseMessage?> GetResponseAsync(
1414
HttpRequestMessage request,
1515
CancellationToken cancellationToken = default
1616
);
@@ -20,7 +20,7 @@ public interface IHttpCache : IAsyncDisposable, IDisposable
2020
/// </summary>
2121
/// <param name="request">The request</param>
2222
/// <returns>The cached response including variation details, or <see langword="null"/> if the response was not found</returns>
23-
ValueTask<ResponseWithVariation?> GetWithVariationAsync(
23+
ValueTask<ResponseWithVariation?> GetResponseWithVariationAsync(
2424
HttpRequestMessage request,
2525
CancellationToken cancellationToken = default
2626
);
@@ -30,7 +30,7 @@ public interface IHttpCache : IAsyncDisposable, IDisposable
3030
/// </summary>
3131
/// <param name="response">The response to set</param>
3232
/// <returns>The cached response, or <see langword="null"/> if the response could not be cached</returns>
33-
Task<HttpResponseMessage?> SetResponseAsync(
33+
ValueTask<HttpResponseMessage?> SetResponseAsync(
3434
HttpResponseMessage response,
3535
CancellationToken cancellationToken = default
3636
);

test/HttpClient.Cache.Tests/File/FileCacheTests.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async Task Get_KeyDoesNotExist()
3535
var request = new HttpRequestMessage(HttpMethod.Get, RepoUrl);
3636

3737
// When
38-
Assert.Null(await _cache.GetAsync(request, TestContext.Current.CancellationToken));
38+
Assert.Null(await _cache.GetResponseAsync(request, TestContext.Current.CancellationToken));
3939

4040
// Then
4141
}
@@ -67,7 +67,10 @@ public async Task Get_WithoutVariation()
6767
);
6868

6969
// When
70-
using var found = await _cache.GetAsync(request, TestContext.Current.CancellationToken);
70+
using var found = await _cache.GetResponseAsync(
71+
request,
72+
TestContext.Current.CancellationToken
73+
);
7174

7275
// Then
7376
Assert.NotNull(found);
@@ -101,7 +104,7 @@ public async Task Get_WithVariation_SharedSingleHeader()
101104
);
102105

103106
// When
104-
using var found = await _cache.GetWithVariationAsync(
107+
using var found = await _cache.GetResponseWithVariationAsync(
105108
request,
106109
TestContext.Current.CancellationToken
107110
);
@@ -135,7 +138,7 @@ public async Task Get_WithVariation_PrivateMultipleHeaders()
135138
);
136139

137140
// When
138-
using var found = await _cache.GetWithVariationAsync(
141+
using var found = await _cache.GetResponseWithVariationAsync(
139142
request,
140143
TestContext.Current.CancellationToken
141144
);
@@ -168,14 +171,17 @@ public async Task Set_ResponseExpiration_WithoutVariation()
168171

169172
// Then
170173
_timeProvider.Advance(TimeSpan.FromSeconds(8));
171-
using var notExpired = await _cache.GetAsync(
174+
using var notExpired = await _cache.GetResponseAsync(
172175
request,
173176
TestContext.Current.CancellationToken
174177
);
175178
Assert.Equal(TimeSpan.FromSeconds(2), notExpired?.Headers.CacheControl?.MaxAge);
176179

177180
_timeProvider.Advance(TimeSpan.FromSeconds(10));
178-
using var expired = await _cache.GetAsync(request, TestContext.Current.CancellationToken);
181+
using var expired = await _cache.GetResponseAsync(
182+
request,
183+
TestContext.Current.CancellationToken
184+
);
179185
Assert.Null(expired);
180186
}
181187

@@ -203,7 +209,7 @@ public async Task Set_ResponseExpiration_WithVariation()
203209
);
204210

205211
// Then
206-
using var notExpired = await _cache.GetWithVariationAsync(
212+
using var notExpired = await _cache.GetResponseWithVariationAsync(
207213
request,
208214
TestContext.Current.CancellationToken
209215
);
@@ -215,7 +221,10 @@ public async Task Set_ResponseExpiration_WithVariation()
215221
);
216222

217223
_timeProvider.Advance(TimeSpan.FromSeconds(20));
218-
using var expired = await _cache.GetAsync(request, TestContext.Current.CancellationToken);
224+
using var expired = await _cache.GetResponseAsync(
225+
request,
226+
TestContext.Current.CancellationToken
227+
);
219228
Assert.Null(expired);
220229
}
221230

@@ -255,14 +264,17 @@ await _cache.RefreshResponseAsync(
255264

256265
// Then
257266
_timeProvider.Advance(TimeSpan.FromSeconds(8));
258-
using var notExpired = await _cache.GetAsync(
267+
using var notExpired = await _cache.GetResponseAsync(
259268
request,
260269
TestContext.Current.CancellationToken
261270
);
262271
Assert.Equal(TimeSpan.FromSeconds(2), notExpired?.Headers.CacheControl?.MaxAge);
263272

264273
_timeProvider.Advance(TimeSpan.FromSeconds(10));
265-
using var expired = await _cache.GetAsync(request, TestContext.Current.CancellationToken);
274+
using var expired = await _cache.GetResponseAsync(
275+
request,
276+
TestContext.Current.CancellationToken
277+
);
266278
Assert.Null(expired);
267279
}
268280

@@ -291,13 +303,16 @@ public async Task Refresh_NoMaxAge()
291303

292304
// Then
293305
_timeProvider.Advance(TimeSpan.FromSeconds(18));
294-
using var notExpired = await _cache.GetAsync(
306+
using var notExpired = await _cache.GetResponseAsync(
295307
request,
296308
TestContext.Current.CancellationToken
297309
);
298310

299311
_timeProvider.Advance(TimeSpan.FromSeconds(10));
300-
using var expired = await _cache.GetAsync(request, TestContext.Current.CancellationToken);
312+
using var expired = await _cache.GetResponseAsync(
313+
request,
314+
TestContext.Current.CancellationToken
315+
);
301316
Assert.Null(expired);
302317
}
303318
}

0 commit comments

Comments
 (0)