obj.cacheable vs expires headers?

Antoni Villalonga antonivillalonga at dorna.com
Tue Feb 2 00:37:03 CET 2010


Hi!

It's seems to be correct. Be careful with cacheable and ttl=0 answers.

Some simple debuging:
sub vcl_fetch {
	# Varnish determined the object was not cacheable
	if (!obj.cacheable) {
		set obj.http.X-Cacheable = "No";
	} elsif (obj.ttl > 0s) {
		set obj.http.X-Cacheable = "Yes";
	} else {
		set obj.http.X-Cacheable = "Yes: ttl=0";
	}
	[...]
}

Good luck!

On dl, feb 01, 2010 at 09:42:58 +0100, Luc Stroobant wrote:
> Hello list,
> 
> I have a vcl-config with a snippet like the one on:
> http://varnish-cache.org/wiki/VCLExampleLongerCaching
> 
> sub vcl_fetch {
>      if (obj.cacheable) {
>        unset obj.http.expires;
>        set obj.http.cache-control = "max-age = 900";
>        set obj.ttl = 2w;
>        set obj.http.magicmarker = "1";
>      }
> }
> 
> sub vcl_deliver {
>      if (resp.http.magicmarker) {
>        /* unset marker and serve it for upstream as new */
>        unset resp.http.magicmarker;
>        set resp.http.age = "0";
>      }
> }
> 
> We used that in an attempt to override the expires headers from static 
> files for a site and keep them in Varnish cache. We don't want to cache 
> an dynamic (PHP) page.
> 
> At first sight, everything went fine. But once the load rised a bit, we 
> noticed that dynamic pages are sometimes cached.
> I've been checking the headers and it looks like the expires header for 
> dynamic pages is also removed. I don't think the headers from the 
> (first) request below should be considerd obj.cacheable  according to 
> the definition on http://varnish-cache.org/wiki/VCL
> Or did I miss something? Is this a mistake in my config or a possible 
> Varnish issue?
> 
> Test without the vcl snippet.
> PHP page: unmodified headers and not cached, as expected:
> 
> HTTP/1.1 200 OK
> Server: Apache/2.2.3 (CentOS)
> X-Powered-By: PHP/5.2.12
> Set-Cookie: SESSbc5f9ce1c97eee1824d1ab6sdfsdfssf70k2hqq7mgo6; 
> expires=Wed, 24-Feb-2010 22:58:21 GMT; path=/; domain=removed
> Expires: Sun, 19 Nov 1978 05:00:00 GMT
> Last-Modified: Mon, 01 Feb 2010 19:25:01 GMT
> Cache-Control: store, no-cache, must-revalidate
> Cache-Control: post-check=0, pre-check=0
> Content-Type: text/html; charset=utf-8
> Content-Length: 56194
> Date: Mon, 01 Feb 2010 19:25:02 GMT
> X-Varnish: 963899298
> Age: 0
> Via: 1.1 varnish
> Connection: close
> 
> 
> With the config:
> PHP page, Expires header removed and cache-control is set
> 
> HTTP/1.1 200 OK
> Server: Apache/2.2.3 (CentOS)
> X-Powered-By: PHP/5.2.12
> Set-Cookie: SESSbc5f9ce1c97eee1824d1ab670ce3057b=91dpgvghvkmonso1; 
> expires=Wed, 24-Feb-2010 23:21:04 GMT; path=/; domain=removed
> Last-Modified: Mon, 01 Feb 2010 19:47:44 GMT
> Content-Type: text/html; charset=utf-8
> Content-Length: 59418
> cache-control: max-age = 900
> Date: Mon, 01 Feb 2010 19:47:48 GMT
> X-Varnish: 1790685114
> Via: 1.1 varnish
> Connection: close
> age: 0
> 
> I used the same VCL-code in vcl_fetch for both examples and for static 
> files, everything works as expected. Any ideas?
> (Running on Varnish 2.0.6)
> 
> Luc
> 
> sub vcl_recv {
> 
>      # Add a unique header containing the client address
>      remove req.http.X-Forwarded-For;
>      set    req.http.X-Forwarded-For = client.ip;
> 
>      /* Don't cache accept */
>      if (req.http.host ~ "^some.host$") {
>        return (pass);
>      }
> 
>      if (req.url ~ "\.(css|js|jpg|jpeg|gif|ico|png)$") {
>      	unset req.http.cookie;
>      	lookup;
>      }
> 
>     /* Never cache php files... */
>     if (req.url ~ ".*\.php") {
>       return (pass);
>     }
> 
>     /* ... or Apache server status */
>     if (req.url ~ ".*/server-status$") {
>       return (pass);
>     }
> }
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at projects.linpro.no
> http://projects.linpro.no/mailman/listinfo/varnish-misc

-- 
Antoni Villalonga i Noceras / root / New Technologies / Dorna Sports S.L.
Tel. +34 934 702 885  / Fax. +34 934 737 779
Narcís Monturiol 2, 08960, Sant Just Desvern - Spain
http://www.motogp.com
http://www.dorna.com

***************************** DISCLAIMER *****************************
This message is intended exclusively for the named person. It may
contain confidential, propietary or legally privileged information. No
confidentiality or privilege is waived or lost by any mistransmission.
If you receive this message in error, please immediately delete it and
all copies of it from your system, destroy any hard copies of it an
notify the sender. Your must not, directly or indirectly, use,
disclose, distribute, print, or copy any part of this message if you
are not the intended recipient.

Please note that internet e-mail neither guarantees the
confidentiality nor the proper receipt of the message sent. If the
addressee of this message does not consent to the use of internet
e-mail, please communicate it to us immediately.

**************************** AVISO LEGAL *****************************

Este mensaje es solamente para la persona a la que va dirigido. Puede
contener información confidencial o legalmente protegida. No hay
renuncia a la confidencialidad o privilegio por cualquier transmisión
mala/errónea. Si usted ha recibido este mensaje por error, le rogamos
que borre de su sistema inmediatamente el mensaje asi como todas sus
copias, destruya todas las copias del mismo de su disco duro y
notifique al remitente. No debe, directa o indirectamente, usar,
revelar, distribuir, imprimir o copiar ninguna de las partes de este
mensaje si no es usted el destinatario.

Nótese que el correo electrónico via Internet no permite asegurar ni
la confidencialidad de los mensajes que se transmiten ni la correcta
recepción de los mismos. En el caso de que el destinatario de este
mensaje no consintiera la utilización del correo electrónico via
Internet, rogamos lo ponga en nuestro conocimiento de manera
inmediata.

**********************************************************************


More information about the varnish-misc mailing list