Skip to content

Commit

Permalink
add caching for static files
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Apr 27, 2024
1 parent acba2bd commit 92e0703
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/web/Jordnaer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Jordnaer.Features.Images;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Jordnaer.Database;
using Microsoft.Net.Http.Headers;

Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
Expand Down Expand Up @@ -101,7 +102,15 @@

app.UseHttpsRedirection();

app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
const int durationInSeconds = 60 * 60 * 24; // 24 hours
ctx.Context.Response.Headers[HeaderNames.CacheControl] =
"public,max-age=" + durationInSeconds;
}
});
app.UseRouting();

app.UseSerilog();
Expand Down

0 comments on commit 92e0703

Please sign in to comment.