-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow GET requests to be cached privately for 5m
At the moment we monkey-patch the Ruby API client library to cache GET request responses for 5 minutes. It was done this way originally as ASP.NET Core was preventing us from setting `Cache-Control` headers on authenticated requests. This no longer seems to be the case and the core team appear to be actively working towards a less opinionated caching implementation. Add a custom attribute for short term (5m), private response caching that is safe to use on most GET responses. Applies it to: - All /types endpoints - All /privacy_policies endpoints - GET /teaching_events endpoints (search and upcoming)
- Loading branch information
1 parent
fb065ef
commit 7845bb0
Showing
8 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
GetIntoTeachingApi/Attributes/PrivateShortTermResponseCacheAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace GetIntoTeachingApi.Attributes | ||
{ | ||
public class PrivateShortTermResponseCacheAttribute : ResponseCacheAttribute | ||
{ | ||
public PrivateShortTermResponseCacheAttribute() | ||
{ | ||
Location = ResponseCacheLocation.Client; | ||
Duration = 300; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
GetIntoTeachingApiTests/Attributes/PrivateShortTermResponseCacheAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using FluentAssertions; | ||
using GetIntoTeachingApi.Attributes; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Xunit; | ||
|
||
namespace GetIntoTeachingApiTests.Attributes | ||
{ | ||
public class PrivateShortTermResponseCacheAttributeTests | ||
{ | ||
[Fact] | ||
public void Constructor_CorrectlySetsCacheControl() | ||
{ | ||
var cache = new PrivateShortTermResponseCacheAttribute(); | ||
|
||
cache.Location.Should().Be(ResponseCacheLocation.Client); | ||
cache.Duration.Should().Be(300); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters