Skip to content

Commit 2d33c91

Browse files
committed
Configurable toggle for output cache
1 parent cee8b72 commit 2d33c91

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ASPNETCORE_ENVIRONMENT=Development
22
ASPNETCORE_HTTP_PORTS=8080
33
KEY_VAULT_NAME=key-vault-name
4+
OUTPUT_CACHE=true

src/Api/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
var config = new ConfigurationBuilder()
99
.SetBasePath(Directory.GetCurrentDirectory())
1010
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
11+
.AddEnvironmentVariables()
1112
.Build();
1213

1314
const string logFormat = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message:lj}{NewLine}{Exception}";
@@ -23,7 +24,7 @@
2324

2425
var builder = WebApplication.CreateBuilder(args);
2526

26-
var keyVaultName = Environment.GetEnvironmentVariable("KEY_VAULT_NAME");
27+
var keyVaultName = builder.Configuration.GetValue<string>("KEY_VAULT_NAME");
2728
if (builder.Environment.IsProduction() && !string.IsNullOrEmpty(keyVaultName))
2829
{
2930
var keyVaultUri = new Uri($"https://{keyVaultName}.vault.azure.net/");
@@ -42,7 +43,7 @@
4243

4344
app.ConfigureEndpoints();
4445

45-
app.ConfigureMiddleware(app.Environment);
46+
app.ConfigureMiddleware(app.Environment, app.Configuration);
4647

4748
await app.RunAsync().ConfigureAwait(false);
4849
}

src/Api/Setup/ApiMiddleware.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Api.Setup;
44

55
internal static class ApiMiddleware
66
{
7-
public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironment environment)
7+
public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironment environment, IConfiguration configuration)
88
{
99
if (environment.IsDevelopment())
1010
{
@@ -13,7 +13,10 @@ public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironm
1313

1414
app.UseRouting();
1515

16-
app.UseOutputCache();
16+
if (configuration.GetValue("OUTPUT_CACHE", true))
17+
{
18+
app.UseOutputCache();
19+
}
1720

1821
const string documentName = "/openapi/v1.json";
1922
const string apiName = "Bitcoin Web API v1";

0 commit comments

Comments
 (0)