how can I make varnish to just cache but don't deliver?

Kristian Lyngstøl kristian at
Mon Jul 5 16:11:24 CEST 2010

On Mon, Jul 5, 2010 at 3:17 PM, Pahud <pahudnet at> wrote:
> vcl_deliver(). So I tried this configuration
> sub vcl_deliver {
>          if (req.http.Cache-Control ~ "just-cache") {
>                error 200 "Cached";
>                return (pass);

return (pass); doesn't work from vcl_deliver, nor is it needed after
an error-statement.

>          }
>     return (deliver);
> }
> But no good luck. I guess vcl_deliver just can't get the value of
>  req.http.Cache-Control.
> Is it still possible to achieve this just with VCL?

Hmm. What you could do is:

In vcl_fetch: if (req.http.Cache-Control ~ "just-cache") { set
obj.http.X-Cache-Only = "true"; }
In vcl_deliver:

if (resp.http.X-Cache-Only == "true") {
    if (obj.hits == 0) {
        error 795 "Cached";
    } else {
        remove resp.http.X-Cache-Only;

I used the error code 795 to differentiate from 200, so you can catch
it in vcl_error and strip most of the content of the error message if
you want to. You may use whatever error code you want, of course.

(I haven't tested this, but I don't see why it shouldn't work, except
perhaps syntax typos).

- Kristian

More information about the varnish-misc mailing list