Skip to content

Commit b708e7f

Browse files
committed
fixed parsing issue
1 parent 9ba890d commit b708e7f

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/WebApi.OutputCache.V2/CacheOutputAttribute.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,16 @@ public override void OnActionExecuting(HttpActionContext actionContext)
205205
if (val == null) return;
206206

207207
var contenttype = _webApiCache.Get<MediaTypeHeaderValue>(cachekey + Constants.ContentTypeKey) ?? responseMediaType;
208-
var contentGenerationTimestamp = DateTimeOffset.Parse(_webApiCache.Get<string>(cachekey + Constants.GenerationTimestampKey));
208+
var contentGeneration = _webApiCache.Get<string>(cachekey + Constants.GenerationTimestampKey);
209+
210+
DateTimeOffset? contentGenerationTimestamp = null;
211+
if (contentGeneration != null)
212+
{
213+
if (DateTimeOffset.TryParse(contentGeneration, out DateTimeOffset parsedContentGenerationTimestamp))
214+
{
215+
contentGenerationTimestamp = parsedContentGenerationTimestamp;
216+
}
217+
};
209218

210219
actionContext.Response = actionContext.Request.CreateResponse();
211220
actionContext.Response.Content = new ByteArrayContent(val);

test/WebApi.OutputCache.V2.Tests/ClientSideTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void maxage_mustrevalidate_headers_correct_with_cacheuntil()
123123
{
124124
var client = new HttpClient(_server);
125125
var result = client.GetAsync(_url + "Get_until25012015_1700").Result;
126-
var clientTimeSpanSeconds = new SpecificTime(2017, 01, 25, 17, 0, 0).Execute(DateTime.Now).ClientTimeSpan.TotalSeconds;
126+
var clientTimeSpanSeconds = new SpecificTime(2019, 01, 25, 17, 0, 0).Execute(DateTime.Now).ClientTimeSpan.TotalSeconds;
127127
var resultCacheControlSeconds = ((TimeSpan) result.Headers.CacheControl.MaxAge).TotalSeconds;
128128
Assert.IsTrue(Math.Round(clientTimeSpanSeconds - resultCacheControlSeconds) == 0);
129129
Assert.IsFalse(result.Headers.CacheControl.MustRevalidate);

test/WebApi.OutputCache.V2.Tests/TestControllers/SampleController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public string Get_s50_exclude_true(int id)
7474
return "test" + id;
7575
}
7676

77-
[CacheOutputUntil(2017,01,25,17,00)]
77+
[CacheOutputUntil(2019,01,25,17,00)]
7878
public string Get_until25012015_1700()
7979
{
8080
return "test";

0 commit comments

Comments
 (0)