Preventing Caching in Varnish Based on Backend Response Header

Uday Kumar uday.polu at indiamart.com
Tue May 28 13:37:44 UTC 2024


Hello Guillaume,
Great to know about this, it should work for us!
will check this out

*Thanks & Regards,*
*Uday Kumar*


On Tue, May 28, 2024 at 5:53 PM Guillaume Quintard <
guillaume.quintard at gmail.com> wrote:

> Hi Uday,
>
> Sure, the classic practice will do nicely:
>
> sub vcl_backend_response {
>     if (beresp.http.that-specific-header) {
>         # TTL should match the time during which that header is unlikely
> to change
>         # do NOT set it to 0s or less (
> https://info.varnish-software.com/blog/hit-for-miss-and-why-a-null-ttl-is-bad-for-you
> )
>         set beresp.ttl = 2m;
>         set beresp.uncacheable = true;
>         return (deliver);
>     }
> }
>
> The main trick here is beresp.uncacheable, you do not have to return
> immediately if you still have modifications/checks to do on that response.
>
> Would that work for you?
>
> --
> Guillaume Quintard
>
>
> On Tue, May 28, 2024 at 4:55 AM Uday Kumar <uday.polu at indiamart.com>
> wrote:
>
>> Hello all,
>>
>> We need to prevent caching in Varnish based on a specific header from the
>> backend.
>>
>> Could you please suggest the best approach to achieve this?
>>
>>
>> *Thanks & Regards,*
>> *Uday Kumar*
>> _______________________________________________
>> varnish-misc mailing list
>> varnish-misc at varnish-cache.org
>> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20240528/bc8e723e/attachment-0001.html>


More information about the varnish-misc mailing list