🐛 Remove the cache in poll

This commit is contained in:
2025-08-05 22:55:26 +08:00
parent 22101c8280
commit 2bbef9b9d1

View File

@@ -31,26 +31,12 @@ public class PollService(AppDatabase db, ICacheService cache)
} }
} }
private const string PollCachePrefix = "poll:";
public async Task<Poll?> GetPoll(Guid id) public async Task<Poll?> GetPoll(Guid id)
{ {
var cacheKey = $"{PollCachePrefix}{id}";
var cachedPoll = await cache.GetAsync<Poll?>(cacheKey);
if (cachedPoll is not null)
return cachedPoll;
var poll = await db.Polls var poll = await db.Polls
.Where(e => e.Id == id) .Where(e => e.Id == id)
.Include(e => e.Questions) .Include(e => e.Questions)
.AsNoTracking()
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
if (poll is null) return null;
poll.Publisher = null;
await cache.SetAsync(cacheKey, poll, TimeSpan.FromMinutes(30));
return poll; return poll;
} }