November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Could you add some Middleware to taget your particular file and add some No Caching Rules
You can do something like this but change to your requirements
public class NoCacheMiddleware
{
private readonly RequestDelegate _next;
public NoCacheMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
context.Response.OnStarting(state =>
{
var httpContext = (HttpContext)state;
httpContext.Response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
httpContext.Response.Headers.Add("Pragma", "no-cache");
httpContext.Response.Headers.Add("Expires", "0");
return Task.CompletedTask;
}, context);
await _next(context);
}
}
Or without Middleware and directly in Startup
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
{
if (context.File.Name.EndsWith(".xlsx"))
{
context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
context.Context.Response.Headers.Add("Pragma", "no-cache");
context.Context.Response.Headers.Add("Expires", "0");
}
}
});
There's an open source addon that tries to solve it in a different way - you can refer to sources for inspiration https://github.com/episerver/EPiServer.CdnSupport
Basically, it modifies URL to include last modification date as a first URL segment - so it still be cached and delivered by CDN, but when it will be changed, new URL will be generated.
Won't work for your case if users bookmark URL; but will work if they use a download page with URLs generated by CMS.
Another similar approach, to not touch this globally - just add any query parameter to generated URL, like ?t={file_last_modified_date} - different query forces CDN to download file directly from server.
Hi, we have an issue where media files are getting cached. We have a scheduled job that replaces an excel file every day, and a page that links to the file. If a user has previously visited the page and revisits the page to download the newly updated file, the user will get the cached file instead. How to prevent caching from happening, or at least set the caching period?