Skip to content

Commit aa89f7c

Browse files
committed
Apply PR feedback
1 parent fcbea07 commit aa89f7c

File tree

9 files changed

+31
-32
lines changed

9 files changed

+31
-32
lines changed

src/Middleware/OutputCaching/src/CachedResponseBody.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.OutputCaching;
88
/// <summary>
99
/// Represents a cached response body.
1010
/// </summary>
11-
public class CachedResponseBody
11+
internal sealed class CachedResponseBody
1212
{
1313
/// <summary>
1414
/// Creates a new <see cref="CachedResponseBody"/> instance.

src/Middleware/OutputCaching/src/IOutputCacheStore.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ public interface IOutputCacheStore
1212
/// Evicts cached responses by tag.
1313
/// </summary>
1414
/// <param name="tag">The tag to evict.</param>
15-
/// <param name="token">Indicates that the operation should be cancelled.</param>
16-
ValueTask EvictByTagAsync(string tag, CancellationToken token);
15+
/// <param name="cancellationToken">Indicates that the operation should be cancelled.</param>
16+
ValueTask EvictByTagAsync(string tag, CancellationToken cancellationToken);
1717

1818
/// <summary>
1919
/// Gets the cached response for the given key, if it exists.
2020
/// If no cached response exists for the given key, <c>null</c> is returned.
2121
/// </summary>
2222
/// <param name="key">The cache key to look up.</param>
23-
/// <param name="token">Indicates that the operation should be cancelled.</param>
23+
/// <param name="cancellationToken">Indicates that the operation should be cancelled.</param>
2424
/// <returns>The response cache entry if it exists; otherwise <c>null</c>.</returns>
25-
ValueTask<byte[]?> GetAsync(string key, CancellationToken token);
25+
ValueTask<byte[]?> GetAsync(string key, CancellationToken cancellationToken);
2626

2727
/// <summary>
2828
/// Stores the given response in the response cache.
@@ -31,6 +31,6 @@ public interface IOutputCacheStore
3131
/// <param name="value">The response cache entry to store.</param>
3232
/// <param name="tags">The tags associated with the cache entry to store.</param>
3333
/// <param name="validFor">The amount of time the entry will be kept in the cache before expiring, relative to now.</param>
34-
/// <param name="token">Indicates that the operation should be cancelled.</param>
35-
ValueTask SetAsync(string key, byte[] value, string[] tags, TimeSpan validFor, CancellationToken token);
34+
/// <param name="cancellationToken">Indicates that the operation should be cancelled.</param>
35+
ValueTask SetAsync(string key, byte[] value, string[] tags, TimeSpan validFor, CancellationToken cancellationToken);
3636
}

src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal MemoryOutputCacheStore(IMemoryCache cache)
1818
_cache = cache;
1919
}
2020

21-
public ValueTask EvictByTagAsync(string tag, CancellationToken token)
21+
public ValueTask EvictByTagAsync(string tag, CancellationToken cancellationToken)
2222
{
2323
ArgumentNullException.ThrowIfNull(tag);
2424

@@ -34,7 +34,7 @@ public ValueTask EvictByTagAsync(string tag, CancellationToken token)
3434
}
3535

3636
/// <inheritdoc />
37-
public ValueTask<byte[]?> GetAsync(string key, CancellationToken token)
37+
public ValueTask<byte[]?> GetAsync(string key, CancellationToken cancellationToken)
3838
{
3939
ArgumentNullException.ThrowIfNull(key);
4040

@@ -43,7 +43,7 @@ public ValueTask EvictByTagAsync(string tag, CancellationToken token)
4343
}
4444

4545
/// <inheritdoc />
46-
public ValueTask SetAsync(string key, byte[] value, string[] tags, TimeSpan validFor, CancellationToken token)
46+
public ValueTask SetAsync(string key, byte[] value, string[] tags, TimeSpan validFor, CancellationToken cancellationToken)
4747
{
4848
ArgumentNullException.ThrowIfNull(key);
4949
ArgumentNullException.ThrowIfNull(value);

src/Middleware/OutputCaching/src/OutputCacheAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.OutputCaching;
77
/// Specifies the parameters necessary for setting appropriate headers in output caching.
88
/// </summary>
99
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
10-
public class OutputCacheAttribute : Attribute
10+
public sealed class OutputCacheAttribute : Attribute
1111
{
1212
// A nullable-int cannot be used as an Attribute parameter.
1313
// Hence this nullable-int is present to back the Duration property.

src/Middleware/OutputCaching/src/OutputCacheEntryFormatter.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace Microsoft.AspNetCore.OutputCaching;
99
/// <summary>
1010
/// Formats <see cref="OutputCacheEntry"/> instance to match structures supported by the <see cref="IOutputCacheStore"/> implementations.
1111
/// </summary>
12-
internal class OutputCacheEntryFormatter
12+
internal static class OutputCacheEntryFormatter
1313
{
14-
public static async ValueTask<OutputCacheEntry?> GetAsync(string key, IOutputCacheStore store, CancellationToken token)
14+
public static async ValueTask<OutputCacheEntry?> GetAsync(string key, IOutputCacheStore store, CancellationToken cancellationToken)
1515
{
1616
ArgumentNullException.ThrowIfNull(key);
1717

18-
var content = await store.GetAsync(key, token);
18+
var content = await store.GetAsync(key, cancellationToken);
1919

2020
if (content == null)
2121
{
@@ -24,7 +24,7 @@ internal class OutputCacheEntryFormatter
2424

2525
using var br = new MemoryStream(content);
2626

27-
var formatter = await JsonSerializer.DeserializeAsync(br, FormatterEntrySerializerContext.Default.FormatterEntry, cancellationToken: token);
27+
var formatter = await JsonSerializer.DeserializeAsync(br, FormatterEntrySerializerContext.Default.FormatterEntry, cancellationToken: cancellationToken);
2828

2929
if (formatter == null)
3030
{
@@ -52,7 +52,7 @@ internal class OutputCacheEntryFormatter
5252
return outputCacheEntry;
5353
}
5454

55-
public static async ValueTask StoreAsync(string key, OutputCacheEntry value, TimeSpan duration, IOutputCacheStore store, CancellationToken token)
55+
public static async ValueTask StoreAsync(string key, OutputCacheEntry value, TimeSpan duration, IOutputCacheStore store, CancellationToken cancellationToken)
5656
{
5757
ArgumentNullException.ThrowIfNull(value);
5858

@@ -75,7 +75,7 @@ public static async ValueTask StoreAsync(string key, OutputCacheEntry value, Tim
7575

7676
using var br = new MemoryStream();
7777

78-
await JsonSerializer.SerializeAsync(br, formatterEntry, FormatterEntrySerializerContext.Default.FormatterEntry, token);
79-
await store.SetAsync(key, br.ToArray(), value.Tags ?? Array.Empty<string>(), duration, token);
78+
await JsonSerializer.SerializeAsync(br, formatterEntry, FormatterEntrySerializerContext.Default.FormatterEntry, cancellationToken);
79+
await store.SetAsync(key, br.ToArray(), value.Tags ?? Array.Empty<string>(), duration, cancellationToken);
8080
}
8181
}

src/Middleware/OutputCaching/src/OutputCacheKeyProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public string CreateStorageKey(OutputCacheContext context)
174174
}
175175
}
176176

177-
private class QueryKeyComparer : IComparer<KeyValuePair<string, StringValues>>
177+
private sealed class QueryKeyComparer : IComparer<KeyValuePair<string, StringValues>>
178178
{
179179
private readonly StringComparer _stringComparer;
180180

src/Middleware/OutputCaching/src/OutputCacheMiddleware.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.OutputCaching;
1414
/// <summary>
1515
/// Enable HTTP response caching.
1616
/// </summary>
17-
internal class OutputCacheMiddleware
17+
internal sealed class OutputCacheMiddleware
1818
{
1919
// see https://tools.ietf.org/html/rfc7232#section-4.1
2020
private static readonly string[] HeadersToIncludeIn304 =
@@ -79,15 +79,19 @@ internal OutputCacheMiddleware(
7979
/// </summary>
8080
/// <param name="httpContext">The <see cref="HttpContext"/>.</param>
8181
/// <returns>A <see cref="Task"/> that completes when the middleware has completed processing.</returns>
82-
public async Task Invoke(HttpContext httpContext)
82+
public Task Invoke(HttpContext httpContext)
8383
{
8484
// Skip the middleware if there is no policy for the current request
8585
if (!TryGetRequestPolicies(httpContext, out var policies))
8686
{
87-
await _next(httpContext);
88-
return;
87+
return _next(httpContext);
8988
}
9089

90+
return InvokeAwaited(httpContext, policies);
91+
}
92+
93+
private async Task InvokeAwaited(HttpContext httpContext, IReadOnlyList<IOutputCachePolicy> policies)
94+
{
9195
var context = new OutputCacheContext(httpContext, _store, _options, _logger);
9296

9397
// Add IOutputCacheFeature

src/Middleware/OutputCaching/src/Policies/VaryByQueryPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.OutputCaching;
1111
/// </summary>
1212
internal sealed class VaryByQueryPolicy : IOutputCachePolicy
1313
{
14-
private StringValues _queryKeys { get; set; }
14+
private readonly StringValues _queryKeys;
1515

1616
/// <summary>
1717
/// Creates a policy that doesn't vary the cached content based on query string.

src/Middleware/OutputCaching/src/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#nullable enable
22
Microsoft.AspNetCore.Builder.OutputCacheApplicationBuilderExtensions
3-
Microsoft.AspNetCore.OutputCaching.CachedResponseBody
4-
Microsoft.AspNetCore.OutputCaching.CachedResponseBody.CachedResponseBody(System.Collections.Generic.List<byte[]!>! segments, long length) -> void
5-
Microsoft.AspNetCore.OutputCaching.CachedResponseBody.CopyToAsync(System.IO.Pipelines.PipeWriter! destination, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
6-
Microsoft.AspNetCore.OutputCaching.CachedResponseBody.Length.get -> long
7-
Microsoft.AspNetCore.OutputCaching.CachedResponseBody.Segments.get -> System.Collections.Generic.List<byte[]!>!
83
Microsoft.AspNetCore.OutputCaching.CachedVaryByRules
94
Microsoft.AspNetCore.OutputCaching.CachedVaryByRules.CachedVaryByRules() -> void
105
Microsoft.AspNetCore.OutputCaching.CachedVaryByRules.Headers.get -> Microsoft.Extensions.Primitives.StringValues
@@ -20,10 +15,10 @@ Microsoft.AspNetCore.OutputCaching.IOutputCachePolicy.CacheRequestAsync(Microsof
2015
Microsoft.AspNetCore.OutputCaching.IOutputCachePolicy.ServeFromCacheAsync(Microsoft.AspNetCore.OutputCaching.OutputCacheContext! context) -> System.Threading.Tasks.ValueTask
2116
Microsoft.AspNetCore.OutputCaching.IOutputCachePolicy.ServeResponseAsync(Microsoft.AspNetCore.OutputCaching.OutputCacheContext! context) -> System.Threading.Tasks.ValueTask
2217
Microsoft.AspNetCore.OutputCaching.IOutputCacheStore
23-
Microsoft.AspNetCore.OutputCaching.IOutputCacheStore.EvictByTagAsync(string! tag, System.Threading.CancellationToken token) -> System.Threading.Tasks.ValueTask
18+
Microsoft.AspNetCore.OutputCaching.IOutputCacheStore.EvictByTagAsync(string! tag, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
2419
Microsoft.AspNetCore.OutputCaching.IOutputCachePolicy
25-
Microsoft.AspNetCore.OutputCaching.IOutputCacheStore.GetAsync(string! key, System.Threading.CancellationToken token) -> System.Threading.Tasks.ValueTask<byte[]?>
26-
Microsoft.AspNetCore.OutputCaching.IOutputCacheStore.SetAsync(string! key, byte[]! value, string![]! tags, System.TimeSpan validFor, System.Threading.CancellationToken token) -> System.Threading.Tasks.ValueTask
20+
Microsoft.AspNetCore.OutputCaching.IOutputCacheStore.GetAsync(string! key, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<byte[]?>
21+
Microsoft.AspNetCore.OutputCaching.IOutputCacheStore.SetAsync(string! key, byte[]! value, string![]! tags, System.TimeSpan validFor, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
2722
Microsoft.AspNetCore.OutputCaching.OutputCacheAttribute
2823
Microsoft.AspNetCore.OutputCaching.OutputCacheAttribute.Duration.get -> int
2924
Microsoft.AspNetCore.OutputCaching.OutputCacheAttribute.Duration.init -> void

0 commit comments

Comments
 (0)