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

Pahud pahudnet at gmail.com
Mon Jul 5 16:49:45 CEST 2010


Thanks for your quick reply. I tried your config and varnish started with no
error but if I send http request in this case, varnish will have empty
response. And if I comment off the vcl_deliver it responds as normal.  Can
you help me a little bit more? Thanks again.

pahud





On Mon, Jul 5, 2010 at 10:11 PM, Kristian Lyngstøl <
kristian at varnish-software.com> wrote:

> On Mon, Jul 5, 2010 at 3:17 PM, Pahud <pahudnet at gmail.com> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20100705/0fd67c2c/attachment-0003.html>


More information about the varnish-misc mailing list