I am trying to get cache working on my API call but every time I do a request it goes straight into my lookup service code.
I have two services, stock and productlookup. The stock calls the productlookup to check to see if there is a product available for the stock.
To reduce the load on the lookup service I wanted to cache the requests to ease the load on the lookup service because the same request will be performed quite a few times. The problem is that even with the caching in place the code in the lookup is still being performed.
My setup code on my lookup service:
app.MapGet("/{ClientCode}/Stock/Lookup/{Sku}", Get)
.WithApiVersionSet(vs)
.Produces<LocationAdjustDto>(StatusCodes.Status200OK)
.Produces<LocationAdjustDto>(StatusCodes.Status404NotFound)
.WithSummary("Get Request.")
.WithOpenApi()
.MapToApiVersion(1)
.CacheOutput();
public async Task<IResult> Get(IStockService stockService, IValidator<StockLookupRequest> validator,
[AsParameters] StockLookupRequest lookupRequest)
{}
My Program.cs file:
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
builder.Host.UseSerilog((context, configuration) => configuration.ReadFrom.Configuration(context.Configuration));
builder.Services.AddHealthChecks();
builder.Services.AddIdentityAuthentication(builder.Configuration, false);
builder.Services.AddUrlSegmentApiVersioning();
builder.Services.AddRepositories(builder.Configuration);
builder.Services.AddLookupService();
builder.Services.AddCarter();
builder.Services.AddOpenApi();
builder.Services.AddAuthorization();
builder.Services.AddOutputCache();
var app = builder.Build();
app.MapCarter();
app.UseOutputCache();
app.UseAuthorization();
app.Run();
We also do have a RequireAuthorization();.
Also calling the Lookup service using the GET request through Bruno doesn't work either.