Re: Logged-in users
Miles skrev: > My question is, how can I organise the cache to have the most cache > hits, given that there are effectively two versions of each page - one > for logged in users, and one for anonymous users. ESI has already been pointed out as the ideal way of handling this. You might also consider issuing a "Vary: $USER" header so Varnish will keep a copy for each user (this might bloat your cache, be careful) or set a custom header for logged inn users (X-foo: logged in as bar) and then pick this header up in vcl_recv and do a "pass" on the relevant request. -- Per Buer - Leder Infrastruktur og Drift - Redpill Linpro Telefon: 21 54 41 21 - Mobil: 958 39 117 http://linpro.no/ | http://redpill.se/ signature.asc Description: OpenPGP digital signature ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Logged-in users
Have a look at ESI: http://varnish.projects.linpro.no/wiki/ESIfeatures Regards, Bjoern Miles wrote: > Hi, > > I have a site where users can log in. This sets a cookie with their > encrypted login details, so they can be authenticated. There are a > small number of pages which are user-specific ("change your details" > forms, etc), and these are set not to cache. > > When a user is logged in, a message is shown at the top of the page "You > are now logged in". However, nothing on the page depends on the > individual user. > > My question is, how can I organise the cache to have the most cache > hits, given that there are effectively two versions of each page - one > for logged in users, and one for anonymous users. I want to > specifically avoid each user having their own version of the page stored > in the cache. > > Thanks in advance for any wisdom anyone can share! > > Miles > > ___ > varnish-misc mailing list > varnish-misc@projects.linpro.no > http://projects.linpro.no/mailman/listinfo/varnish-misc ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Logged-in users
We do both depending on scenario: we use ajax to update parts of a page after-delivery (poor mans ESI ;) as suggested by Tim, and we also have a custom vcl_hash that caches different copies of pages depending on various cookies and other conditions (much as Miles suggests). Both fit depending on the use-case. Miles: FWIW, the CacheFu product for Plone may assist you to maximise the caching potential of your site without too many custom tweaks to your Varnish rules. regards, Darryl Dixon Winterhouse Consulting Ltd http://www.winterhouseconsulting.com > Another approach is to simply use a small bit of Javascript. It's > easy to test for the existence of the cookie in Javascript and > set that text conditionally. > > Then you have only one copy of the page to be cached. > > The problem with the approach you've outlined here is > that other downstream caches won't understand the difference > (although most will simply refuse to cache any responses > if the request had a cookie header). Whereas the Javascript > approach also allows downstream caches to cache everything > efficiently. > > Tim > > > > On Nov 26, 2008, at 12:31 PM, Miles wrote: > >> Miles wrote: >>> Hi, >>> >>> I have a site where users can log in. This sets a cookie with their >>> encrypted login details, so they can be authenticated. There are a >>> small number of pages which are user-specific ("change your details" >>> forms, etc), and these are set not to cache. >>> >>> When a user is logged in, a message is shown at the top of the page >>> "You >>> are now logged in". However, nothing on the page depends on the >>> individual user. >>> >>> My question is, how can I organise the cache to have the most cache >>> hits, given that there are effectively two versions of each page - >>> one >>> for logged in users, and one for anonymous users. I want to >>> specifically avoid each user having their own version of the page >>> stored >>> in the cache. >>> >>> Thanks in advance for any wisdom anyone can share! >>> >>> Miles >> >> Thanks to everyone who suggested using ESI - I may have to use this, >> but >> would quite like to avoid it, as it's useful to be able to run the app >> without varnish in front for development/testing. >> >> I wondered whether it was possible to use vcl_hash for my purposes, as >> follows: >> >> sub vcl_hash { >> >>//hash the object with url+host >>set req.hash += req.url; >>set req.hash += req.http.host; >> >># see if the user has a cookie to indicate they are logged in >>if req.http.cookie ~ '__ac=': >> set req.hash += 'authenticated'; >>else: >> set req.hash += 'anonymous' >>hash; >> >> } >> >> Would this give me the two representations that I require for each >> page >> - or am I going down a route that will turn out bad?! I couldn't find >> much information about vcl_hash, so I'm not sure if I'm barking up the >> wrong tree or not... >> >> Regards, >> >> Miles >> >> ___ >> varnish-misc mailing list >> varnish-misc@projects.linpro.no >> http://projects.linpro.no/mailman/listinfo/varnish-misc > > ___ > varnish-misc mailing list > varnish-misc@projects.linpro.no > http://projects.linpro.no/mailman/listinfo/varnish-misc > ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Logged-in users
Another approach is to simply use a small bit of Javascript. It's easy to test for the existence of the cookie in Javascript and set that text conditionally. Then you have only one copy of the page to be cached. The problem with the approach you've outlined here is that other downstream caches won't understand the difference (although most will simply refuse to cache any responses if the request had a cookie header). Whereas the Javascript approach also allows downstream caches to cache everything efficiently. Tim On Nov 26, 2008, at 12:31 PM, Miles wrote: > Miles wrote: >> Hi, >> >> I have a site where users can log in. This sets a cookie with their >> encrypted login details, so they can be authenticated. There are a >> small number of pages which are user-specific ("change your details" >> forms, etc), and these are set not to cache. >> >> When a user is logged in, a message is shown at the top of the page >> "You >> are now logged in". However, nothing on the page depends on the >> individual user. >> >> My question is, how can I organise the cache to have the most cache >> hits, given that there are effectively two versions of each page - >> one >> for logged in users, and one for anonymous users. I want to >> specifically avoid each user having their own version of the page >> stored >> in the cache. >> >> Thanks in advance for any wisdom anyone can share! >> >> Miles > > Thanks to everyone who suggested using ESI - I may have to use this, > but > would quite like to avoid it, as it's useful to be able to run the app > without varnish in front for development/testing. > > I wondered whether it was possible to use vcl_hash for my purposes, as > follows: > > sub vcl_hash { > >//hash the object with url+host >set req.hash += req.url; >set req.hash += req.http.host; > ># see if the user has a cookie to indicate they are logged in >if req.http.cookie ~ '__ac=': > set req.hash += 'authenticated'; >else: > set req.hash += 'anonymous' >hash; > > } > > Would this give me the two representations that I require for each > page > - or am I going down a route that will turn out bad?! I couldn't find > much information about vcl_hash, so I'm not sure if I'm barking up the > wrong tree or not... > > Regards, > > Miles > > ___ > varnish-misc mailing list > varnish-misc@projects.linpro.no > http://projects.linpro.no/mailman/listinfo/varnish-misc ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Re: Logged-in users
Miles wrote: > Hi, > > I have a site where users can log in. This sets a cookie with their > encrypted login details, so they can be authenticated. There are a > small number of pages which are user-specific ("change your details" > forms, etc), and these are set not to cache. > > When a user is logged in, a message is shown at the top of the page "You > are now logged in". However, nothing on the page depends on the > individual user. > > My question is, how can I organise the cache to have the most cache > hits, given that there are effectively two versions of each page - one > for logged in users, and one for anonymous users. I want to > specifically avoid each user having their own version of the page stored > in the cache. > > Thanks in advance for any wisdom anyone can share! > > Miles Thanks to everyone who suggested using ESI - I may have to use this, but would quite like to avoid it, as it's useful to be able to run the app without varnish in front for development/testing. I wondered whether it was possible to use vcl_hash for my purposes, as follows: sub vcl_hash { //hash the object with url+host set req.hash += req.url; set req.hash += req.http.host; # see if the user has a cookie to indicate they are logged in if req.http.cookie ~ '__ac=': set req.hash += 'authenticated'; else: set req.hash += 'anonymous' hash; } Would this give me the two representations that I require for each page - or am I going down a route that will turn out bad?! I couldn't find much information about vcl_hash, so I'm not sure if I'm barking up the wrong tree or not... Regards, Miles ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Logged-in users
Hi, I have a site where users can log in. This sets a cookie with their encrypted login details, so they can be authenticated. There are a small number of pages which are user-specific ("change your details" forms, etc), and these are set not to cache. When a user is logged in, a message is shown at the top of the page "You are now logged in". However, nothing on the page depends on the individual user. My question is, how can I organise the cache to have the most cache hits, given that there are effectively two versions of each page - one for logged in users, and one for anonymous users. I want to specifically avoid each user having their own version of the page stored in the cache. Thanks in advance for any wisdom anyone can share! Miles ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc
Logged-in users
Hi, I have a site where users can log in. This sets a cookie with their encrypted login details, so they can be authenticated. There are a small number of pages which are user-specific ("change your details" forms, etc), and these are set not to cache. When a user is logged in, a message is shown at the top of the page "You are now logged in". However, nothing on the page depends on the individual user. My question is, how can I organise the cache to have the most cache hits, given that there are effectively two versions of each page - one for logged in users, and one for anonymous users. Thanks, Miles ___ varnish-misc mailing list varnish-misc@projects.linpro.no http://projects.linpro.no/mailman/listinfo/varnish-misc