cache-able static files (max-age) extensions method
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace zero.Media;
|
||||
|
||||
public static class MediaApplicationBuilderExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseStaticFilesWithCache(this IApplicationBuilder app, TimeSpan cacheDuration)
|
||||
{
|
||||
return app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
OnPrepareResponse = ctx =>
|
||||
{
|
||||
ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public, must-revalidate, max-age=" + (int)cacheDuration.TotalSeconds;
|
||||
},
|
||||
OnPrepareResponseAsync = async ctx =>
|
||||
{
|
||||
await Task.Delay(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using SixLabors.ImageSharp.Web.Caching;
|
||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||
using System.IO;
|
||||
using zero.Media.ImageSharp;
|
||||
using zero.Numbers;
|
||||
using zero.Media.ImageSharp.Processors;
|
||||
|
||||
namespace zero.Media;
|
||||
|
||||
Reference in New Issue
Block a user