-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cache clear endpoint and ignoring cache when in preview (#107)
* Added cache clear endpoint and ignoring cache when in preview * Added some tests for caching * modifed cache controller to API type + respond with OK * removed unused controller map --------- Co-authored-by: Tom Whittington <[email protected]> Co-authored-by: simonjfirth <[email protected]>
- Loading branch information
1 parent
da53160
commit b9ea2ef
Showing
10 changed files
with
103 additions
and
12 deletions.
There are no files selected for viewing
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 Dfe.ContentSupport.Web.Models.Mapped; | ||
using Dfe.ContentSupport.Web.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Dfe.ContentSupport.Web.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class CacheController(ICacheService<List<CsPage>> cache) : Controller | ||
{ | ||
[HttpGet] | ||
[Route("clear")] | ||
public IActionResult Clear() | ||
{ | ||
cache.ClearCache(); | ||
|
||
return Ok(); | ||
} | ||
} |
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
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
17 changes: 17 additions & 0 deletions
17
tests/Dfe.ContentSupport.Web.Tests/Controllers/CacheControllerTests.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,17 @@ | ||
using Dfe.ContentSupport.Web.Controllers; | ||
using Dfe.ContentSupport.Web.Models.Mapped; | ||
|
||
namespace Dfe.ContentSupport.Web.Tests.Controllers; | ||
|
||
public class CacheControllerTests | ||
{ | ||
[Fact] | ||
public void Clear_Calls_CacheClear() | ||
{ | ||
var cacheServiceMock = new Mock<ICacheService<List<CsPage>>>(); | ||
var sut = new CacheController(cacheServiceMock.Object); | ||
sut.Clear(); | ||
|
||
cacheServiceMock.Verify(o => o.ClearCache(), Times.Once); | ||
} | ||
} |
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