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

Pahud pahudnet at gmail.com
Tue Jul 6 12:23:15 CEST 2010


I tried varnishd (varnish-2.1.2 SVN 4769:4772) on Gentoo Linux today. And
the VCL compilation failed:

Message from VCC-compiler:
Variable 'obj.http.X-Cache-Only' not accessible in method 'vcl_fetch'.
At: (input Line 106 Pos 21)
                set obj.http.X-Cache-Only = "true";
--------------------#####################----------
Running VCC-compiler failed, exit 1
VCL compilation failed

I also tried
set resp.http.X-Cache-Only = "true";
but still failed.

:(

pahud


On Mon, Jul 5, 2010 at 10:49 PM, Pahud <pahudnet at gmail.com> wrote:

> 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/20100706/e7f01081/attachment-0003.html>


More information about the varnish-misc mailing list