Skip to content

Commit 80cf69b

Browse files
committed
Include the variation key in the response metadata
1 parent a5a9003 commit 80cf69b

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/HttpClient.Cache/Files/FileCache.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ TimeProvider timeProvider
214214

215215
var now = _timeProvider.GetUtcNow();
216216
var cachedResponse = await SetResponseImplAsync(
217+
variationKey: null,
217218
responseKey,
218219
response,
219220
now,
@@ -242,6 +243,7 @@ TimeProvider timeProvider
242243

243244
// Write the response
244245
var cachedResponse = await SetResponseImplAsync(
246+
variationKey,
245247
responseKey,
246248
response,
247249
now,
@@ -268,6 +270,7 @@ TimeProvider timeProvider
268270
}
269271

270272
private async Task<HttpResponseMessage> SetResponseImplAsync(
273+
string? variationKey,
271274
string responseKey,
272275
HttpResponseMessage response,
273276
DateTimeOffset now,
@@ -278,7 +281,8 @@ CancellationToken cancellationToken
278281
var expiration = response.GetExpiration(now) ?? (now + DefaultInitialExpiration);
279282
var metadata = new MetadataModel()
280283
{
281-
Key = responseKey,
284+
VariationKey = variationKey,
285+
ResponseKey = responseKey,
282286
Url = response.RequestMessage!.RequestUri!,
283287
Version = response.Version,
284288
StatusCode = response.StatusCode,

src/HttpClient.Cache/Files/MetadataModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ namespace HttpClientCache.Files;
44

55
public record MetadataModel
66
{
7-
public required string Key { get; init; }
7+
public required string? VariationKey { get; init; }
8+
public required string ResponseKey { get; init; }
89
public required Uri Url { get; init; }
910
public required Version Version { get; init; }
1011
public required HttpStatusCode StatusCode { get; init; }

src/HttpClient.Cache/Files/VariationFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public readonly async ValueTask WriteAsync(string key, Variation variation)
5252
{
5353
var model = new VariationModel
5454
{
55-
Key = key,
55+
VariationKey = key,
5656
CacheType = variation.CacheType,
5757
NormalizedVaryHeaders = variation.NormalizedVaryHeaders,
5858
};

src/HttpClient.Cache/Files/VariationModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
internal class VariationModel
44
{
5-
public required string Key { get; init; } = string.Empty;
5+
public required string VariationKey { get; init; }
66
public required CacheType CacheType { get; init; }
77
public required List<string> NormalizedVaryHeaders { get; init; }
88
}

0 commit comments

Comments
 (0)