public async Task <IEnumerable <CategoryDto> > Handle(GetCategoriesQuery request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } return(await _redisCacheService.GetOrSetAsync(CacheKeys.CategoriesKey, async() => { Func <MainDbContext, IAsyncEnumerable <Category> > getCategoriesHandler = EF.CompileAsyncQuery((MainDbContext context) => context.Categories.AsNoTracking()); var categories = await getCategoriesHandler(_dbContext).ToListAsync(cancellationToken); return categories.Select(x => new CategoryDto { Id = x.Id, Name = x.Name }); })); }