Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.

Commit 36916d4

Browse files
committed
Some feedback
1 parent faa0b6e commit 36916d4

File tree

5 files changed

+11
-35
lines changed

5 files changed

+11
-35
lines changed

src/Microsoft.AspNetCore.ResponseCaching/Internal/DefaultResponseCacheEntrySerializer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static object Read(BinaryReader reader)
7171
}
7272

7373
// Serialization Format
74-
// Creation time (DateTimeOffset, RoundTripFormat, InvariantCulture)
74+
// Creation time - UtcTicks (long)
7575
// Status code (int)
7676
// Header count (int)
7777
// Header(s)
@@ -81,7 +81,7 @@ public static object Read(BinaryReader reader)
8181
// Body (byte[])
8282
private static CachedResponse ReadCachedResponse(BinaryReader reader)
8383
{
84-
var created = DateTimeOffset.ParseExact(reader.ReadString(), RoundTripFormat, CultureInfo.InvariantCulture);
84+
var created = new DateTimeOffset(reader.ReadInt64(), TimeSpan.Zero);
8585
var statusCode = reader.ReadInt32();
8686
var headerCount = reader.ReadInt32();
8787
var headers = new HeaderDictionary();
@@ -139,7 +139,7 @@ public static void Write(BinaryWriter writer, object entry)
139139
private static void WriteCachedResponse(BinaryWriter writer, CachedResponse entry)
140140
{
141141
writer.Write(nameof(CachedResponse));
142-
writer.Write(entry.Created.ToString(RoundTripFormat, CultureInfo.InvariantCulture));
142+
writer.Write(entry.Created.UtcTicks);
143143
writer.Write(entry.StatusCode);
144144
writer.Write(entry.Headers.Count);
145145
foreach (var header in entry.Headers)

src/Microsoft.AspNetCore.ResponseCaching/Internal/Helpers.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ internal async Task<bool> TryServeFromCacheAsync()
374374

375375
if (body.Length > 0)
376376
{
377-
await response.Body.WriteAsync(body, 0, body.Length).SupressContext();
377+
await response.Body.WriteAsync(body, 0, body.Length);
378378
}
379379

380380
responseServed = true;

src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingMiddleware.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.IO;
65
using System.Threading.Tasks;
76
using Microsoft.AspNetCore.Http;
8-
using Microsoft.AspNetCore.ResponseCaching.Internal;
97

108
namespace Microsoft.AspNetCore.ResponseCaching
119
{
@@ -14,6 +12,11 @@ public class ResponseCachingMiddleware
1412
{
1513
private readonly RequestDelegate _next;
1614
private readonly IResponseCache _cache;
15+
private static readonly Func<object, Task> OnStartingCallback = state =>
16+
{
17+
((ResponseCachingContext)state).OnResponseStarting();
18+
return Task.FromResult(0);
19+
};
1720

1821
public ResponseCachingMiddleware(RequestDelegate next, IResponseCache cache)
1922
{
@@ -50,11 +53,7 @@ public async Task Invoke(HttpContext context)
5053
cachingContext.HookResponseStream();
5154

5255
// Subscribe to OnStarting event
53-
context.Response.OnStarting(state =>
54-
{
55-
(state as ResponseCachingContext).OnResponseStarting();
56-
return Helpers.CompletedTask;
57-
}, cachingContext);
56+
context.Response.OnStarting(OnStartingCallback, cachingContext);
5857

5958
await _next(context);
6059

test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingContextTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ private class TestHttpSendFileFeature : IHttpSendFileFeature
494494
{
495495
public Task SendFileAsync(string path, long offset, long? count, CancellationToken cancellation)
496496
{
497-
return Helpers.CompletedTask;
497+
return Task.FromResult(0);
498498
}
499499
}
500500
}

0 commit comments

Comments
 (0)