Skip to content

Commit

Permalink
feat(cache): add caching for most apis that will rarely change
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Jan 19, 2025
1 parent 22951ad commit 2b1c8c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/GZCTF/Controllers/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class GameController(
/// <param name="token"></param>
/// <response code="200">Successfully retrieved game information</response>
[HttpGet("Recent")]
[ResponseCache(Duration = 300)]
[ProducesResponseType(typeof(BasicGameInfoModel[]), StatusCodes.Status200OK)]
public async Task<IActionResult> RecentGames(
[FromQuery][Range(0, 50)] int limit,
Expand Down
6 changes: 6 additions & 0 deletions src/GZCTF/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class InfoController(
/// <param name="token"></param>
/// <response code="200">Successfully retrieved posts</response>
[HttpGet("Posts/Latest")]
[ResponseCache(Duration = 300)]
[ProducesResponseType(typeof(PostInfoModel[]), StatusCodes.Status200OK)]
public async Task<IActionResult> GetLatestPosts(CancellationToken token) =>
Ok((await postRepository.GetPosts(token)).Take(20).Select(PostInfoModel.FromPost));
Expand All @@ -53,6 +54,8 @@ public async Task<IActionResult> GetLatestPosts(CancellationToken token) =>
/// <param name="token"></param>
/// <response code="200">Successfully retrieved posts</response>
[HttpGet("Posts")]
[ResponseCache(Duration = 300)]
[EnableRateLimiting(nameof(RateLimiter.LimitPolicy.Query))]
[ProducesResponseType(typeof(PostInfoModel[]), StatusCodes.Status200OK)]
public async Task<IActionResult> GetPosts(CancellationToken token) =>
Ok((await postRepository.GetPosts(token)).Select(PostInfoModel.FromPost));
Expand All @@ -68,6 +71,7 @@ public async Task<IActionResult> GetPosts(CancellationToken token) =>
/// <response code="200">Successfully retrieved post details</response>
/// <response code="404">Post not found</response>
[HttpGet("Posts/{id}")]
[ResponseCache(Duration = 300)]
[ProducesResponseType(typeof(PostDetailModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RequestResponse), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetPost(string id, CancellationToken token)
Expand All @@ -89,6 +93,7 @@ public async Task<IActionResult> GetPost(string id, CancellationToken token)
/// </remarks>
/// <response code="200">Successfully retrieved configuration</response>
[HttpGet("Config")]
[ResponseCache(Duration = 300)]
[ProducesResponseType(typeof(ClientConfig), StatusCodes.Status200OK)]
public async Task<IActionResult> GetClientConfig(CancellationToken token = default)
{
Expand All @@ -111,6 +116,7 @@ public async Task<IActionResult> GetClientConfig(CancellationToken token = defau
/// </remarks>
/// <response code="200">Successfully retrieved Captcha configuration</response>
[HttpGet("Captcha")]
[ResponseCache(Duration = 300)]
[ProducesResponseType(typeof(ClientCaptchaInfoModel), StatusCodes.Status200OK)]
public async Task<IActionResult> GetClientCaptchaInfo(CancellationToken token = default)
{
Expand Down

0 comments on commit 2b1c8c6

Please sign in to comment.