Our site has a number of large PDF and MP3 files which we would like to cache in Varnish as static files. Currently we don't do much special - simply remove the cookies in vcl_recv
and set resetp.ttl = 100w;
in vcl_fetch
.
The problem seems to be when one of these files is requested (maybe by older browsers) and it's not already in the Varnish cache. There is a delay while Varnish downloads the file from the backend. My understanding is that it doesn't start delivering to the client until the data is fully loaded. This may take 20 seconds or so and sometimes Adobe Acrobat or the MP3 plugin get confused.
Is there a way to both pass
the content directly while download and save it in the cache for the next matching client request?
Reading suggestion: https://www.varnish-software.com/blog/http-streaming-varnish
With vanilla Varnish 3.0 you could set beresp.do_stream to true in vcl_fetch. The file will be streamed while it is fetched from backend. The caveat: The object is set to busy while streaming, so other clients will be put on hold.
There is also a Varnish 3.0.2 release with baked in "full" streaming support available: http://repo.varnish-cache.org/test/3.0.2+streaming/ which people are using in production, so maybe you want to give it a try.
Or maybe you could "prewarm" your files, placing them in the Varnish memory cache before users start downloading it?
The 3.0.2+streaming branch is not up-to-date anymore and it is only supported for Varnish Plus subscribers, no community support on that.
So if you need streaming capabilities you can either:
Varnish 5.1.2 does exactly what you want with the default config.
I tried it with server sent events where I need streaming first request and cached second request. It just works.