Skip to content

Commit

Permalink
fix(game): fail to flush game list cache
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Jan 18, 2025
1 parent aecb186 commit bf6360f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/GZCTF/Repositories/GameRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class GameRepository(
await SaveAsync(token);

await cacheHelper.FlushGameListCache(token);
await cacheHelper.FlushRecentGamesCache(token);

return game;
}
Expand Down Expand Up @@ -87,8 +88,7 @@ public async Task<ArrayResponse<BasicGameInfoModel>> GetGameInfo(int count = 20,

var games = await cache.GetOrCreateAsync(logger, CacheKey.GameList, entry =>
{
entry.SlidingExpiration = TimeSpan.FromDays(3);

entry.SlidingExpiration = TimeSpan.FromDays(2);
return FetchGameList(100, 0, token);
}, token);

Expand All @@ -99,7 +99,6 @@ public async Task<BasicGameInfoModel[]> GetRecentGames(CancellationToken token =
=> await cache.GetOrCreateAsync(logger, CacheKey.RecentGames, entry =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1);

return GenRecentGames(token);
}, token);

Expand Down Expand Up @@ -205,8 +204,8 @@ public async Task<TaskStatus> DeleteGame(Game game, CancellationToken token = de
await SaveAsync(token);
await trans.CommitAsync(token);

await cacheHelper.FlushRecentGamesCache(token);
await cacheHelper.FlushGameListCache(token);
await cacheHelper.FlushRecentGamesCache(token);

await cache.RemoveAsync(CacheKey.ScoreBoard(game.Id), token);

Expand Down
6 changes: 3 additions & 3 deletions src/GZCTF/Services/Cache/Handlers/GameListCacheHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public async Task<byte[]> Handler(AsyncServiceScope scope, CacheRequest request,
}
catch (Exception e)
{
var logger = scope.ServiceProvider.GetRequiredService<ILogger<RecentGamesCacheHandler>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<GameListCacheHandler>>();
logger.LogError(e, "{msg}",
Program.StaticLocalizer[nameof(Resources.Program.Cache_GenerationFailed), CacheKey(request)!]);
return [];
}
}

public static CacheRequest MakeCacheRequest() =>
new(Cache.CacheKey.RecentGames,
new() { SlidingExpiration = TimeSpan.FromHours(1) });
new(Cache.CacheKey.GameList,
new() { SlidingExpiration = TimeSpan.FromDays(2) });
}

0 comments on commit bf6360f

Please sign in to comment.