Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Varnish: Misc

influencing beresp.cacheable on the backend

 

 

Varnish misc RSS feed   Index | Next | Previous | View Threaded


david.birdsong at gmail

Apr 12, 2010, 2:50 PM

Post #1 of 4 (4434 views)
Permalink
influencing beresp.cacheable on the backend

How can I influence bereps.cacheable in a backend such that it will
evaluate to False?

I set Expires and Cache-Control in the backend, this is what the
backend generates:
HTTP/1.1 200 OK
Server: nginx/0.7.65
Date: Mon, 12 Apr 2010 21:48:25 GMT
Content-Type: image/gif
Content-Length: 43
Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT
Connection: close
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache

From the man page:
"""
A response is considered cacheable if it is valid (see above), the
HTTP status code is 200, 203, 300, 301, 302, 404 or 410 and it has a
non-zero time-to-live when Expires and Cache-Control headers are taken
into account.
"""

And yet this object is getting cached in varnish. Here is my vcl_fetch:


sub vcl_fetch {
if (beresp.http.Set-Cookie) {
unset beresp.http.Set-Cookie;
}

if (beresp.cacheable) {
unset beresp.http.expires;
set beresp.ttl = 1h;

if (beresp.status >= 300 && beresp.status <= 399) {
set beresp.ttl = 10m;
}

if (beresp.status >= 399) {
set beresp.ttl = 0s;
}
}

remove beresp.http.X-Varnish-IP;
remove beresp.http.X-Varnish-Port;
}

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
http://lists.varnish-cache.org/mailman/listinfo/varnish-misc


l at lrowe

Apr 12, 2010, 4:49 PM

Post #2 of 4 (4397 views)
Permalink
Re: influencing beresp.cacheable on the backend [In reply to]

On 12 April 2010 22:50, David Birdsong <david.birdsong [at] gmail> wrote:
> How can I influence bereps.cacheable in a backend such that it will
> evaluate to False?

beresp.cacheable is not re-evaluated. Decide whether to cache an
object or not by either returning pass or deliver, as is done by the
default VCL:

sub vcl_fetch {
if (!beresp.cacheable) {
return (pass);
}
if (beresp.http.Set-Cookie) {
return (pass);
}
return (deliver);
}

Laurence

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
http://lists.varnish-cache.org/mailman/listinfo/varnish-misc


david.birdsong at gmail

Apr 12, 2010, 4:58 PM

Post #3 of 4 (4405 views)
Permalink
Re: influencing beresp.cacheable on the backend [In reply to]

On Mon, Apr 12, 2010 at 4:49 PM, Laurence Rowe <l [at] lrowe> wrote:
> On 12 April 2010 22:50, David Birdsong <david.birdsong [at] gmail> wrote:
>> How can I influence bereps.cacheable in a backend such that it will
>> evaluate to False?
>
> beresp.cacheable is not re-evaluated. Decide whether to cache an
> object or not by either returning pass or deliver, as is done by the
> default VCL:
>
Ok, but what I'm trying to figure out is what does it take in a
backend response for beresp.cacheable to be False. The backend set
'Cache-Control: no-cache' and 'Expires: <epoch>', shouldn't that
response be uncacheable? I'm finding that that response is cached.

> sub vcl_fetch {
>    if (!beresp.cacheable) {
>        return (pass);
>    }
>    if (beresp.http.Set-Cookie) {
>        return (pass);
>    }
>    return (deliver);
> }
>
> Laurence
>

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
http://lists.varnish-cache.org/mailman/listinfo/varnish-misc


tfheen at varnish-software

Apr 18, 2010, 11:22 PM

Post #4 of 4 (4401 views)
Permalink
Re: influencing beresp.cacheable on the backend [In reply to]

]] David Birdsong

| How can I influence bereps.cacheable in a backend such that it will
| evaluate to False?
|
| I set Expires and Cache-Control in the backend, this is what the
| backend generates:
| HTTP/1.1 200 OK
| Server: nginx/0.7.65
| Date: Mon, 12 Apr 2010 21:48:25 GMT
| Content-Type: image/gif
| Content-Length: 43
| Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT
| Connection: close
| Expires: Thu, 01 Jan 1970 00:00:01 GMT
| Cache-Control: no-cache
|
| From the man page:
| """
| A response is considered cacheable if it is valid (see above), the
| HTTP status code is 200, 203, 300, 301, 302, 404 or 410 and it has a
| non-zero time-to-live when Expires and Cache-Control headers are taken
| into account.
| """

The documentation is wrong for 2.1.0, it's correct for 2.0.x. I'm sorry
the docs were wrong, I've updated them now.

| And yet this object is getting cached in varnish. Here is my vcl_fetch:

You can set beresp.cacheable based on the TTL, something like this
should work:

sub vcl_fetch {
if (beresp.ttl < 1s) {
set beresp.cacheable = false;
}
}

--
Tollef Fog Heen
Varnish Software
t: +47 21 54 41 73

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
http://lists.varnish-cache.org/mailman/listinfo/varnish-misc

Varnish misc RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.