Time-of-day caching?

António P. P. Almeida appa at perusio.net
Wed Mar 2 18:54:41 MSK 2011

On 1 Mar 2011 17h04 WET, guzman.braso at gmail.com wrote:

> Hi there,
> We are currently using wordpress (many of them) running in apache
> with nginx in front of it using proxy_cache.
> Currently we are not managing anymore the wordpress and our
> customers do with them as they wish, some have cache enabled, some
> not.  We wanted to use that module but as our customer have many
> different versions of wordpress it didn't fit for us.

Yes. It's tricky. But a very good solution, since you can just use
"one cache to rule them all".

> Right now we cache every static file for a day and all posts for 10
> minutes. To deal with the dynamic content (comments) we create a
> cache_key that uses the wordpress comment author cookie, so users do
> not feel the cache of the posts when submitting comments but it's
> just a perception, in fact the 10 minutes it's still happening it's
> just they do not see it.

Do you use ajax to update only fragments of the page and leave the
remainder unchanged?

> Our current config for this it's not rocket science but if anyone
> want it I would gladly share it.
> Regarding drupal may I send you later an e-mail asking for a tip? I
> want to cache a few hundred drupal sites with nginx and right now
> I'm passing to apache all pages requests as I've not found yet a
> nice way to deal with drupal creating a php session cookie for every
> user and as comments do not go to a specific url neither create a
> unique cookie, I can't detect them so easy as in wordpress.

Sure you can. May I suggest also for you to drop by the Nginx group at
groups.drupal.org? http://groups.drupal.org/nginx

Drupal 7 serves no cookie for anon users. Drupal 6 does. Unless you're
using pressflow, which doesn't. The removal of the cookie is related
to caching strategies.

When you post a comment there are specific patterns on the URI. Other
option is creating a module that sets a cookie when posting comments,
similar to what WP does.

> By the way, does anyone have in hand a simple way to use proxy_cache
> for all requests except POST ?

How about setting a var that busts the cache when non zero. E.g.:

if ($request_method = POST) {
  set $no_cache 1;

then use it in http://wiki.nginx.org/HttpProxyModule#proxy_no_cache

--- appa

More information about the nginx mailing list