Cache the assets

2025/11/10 5:54 AM

Hello, I have content asset type in my project which contains various type of images. I want to set the cache time for them. By default cloud fare is setting it to 4 hours.

In my local setup it is not setting up the cache and when deployed cloud fare set it to 4 hours.

I have found documentation on setting the cache for static files. Wan ted to if there is way to set the cache for images and documents stored in kentico. Please note that for saas platform all the assets are stored in azure blob storage.


Environment

  • Xperience by Kentico version: [30.10.1]

  • .NET version: [8]

  • Execution environment: [SaaS]

Tags:
SEO ASP.NET Core Environments

Answers

2025/11/10 11:02 AM
Accepted answer

I haven't tested this solution, but this is my thesis: you can set cache headers for content assets (images/documents) stored in Kentico, even when served from Azure Blob Storage in SaaS. Something very similar I advocated in this thread.

Use middleware with Response.OnStarting() to set Cache-Control headers based on content type. Content assets go through the ASP.NET Core pipeline, so middleware can intercept and set headers before Cloudflare receives them.

Create middleware that:

  • Checks Response.ContentType for images/documents.

  • Sets Cache-Control headers in Response.OnStarting().

  • Is registered after app.UseKentico() and app.Kentico().MapRoutes().

context.Response.OnStarting(() =>
{
    if (IsImageContentType(context.Response.ContentType))
    {
        context.Response.Headers["Cache-Control"] = "public,max-age=31536000"; // 1 year
    }
    return Task.CompletedTask;
});

Even though assets are in Azure Blob Storage, they're served through Kentico's pipeline, so your headers are included in the response. Cloudflare will respect these headers instead of its default 4-hour cache.

To response this discussion, you have to login first.