Forum

X-Hiawatha-Cache

Martijn
14 October 2013, 21:15
I'm building a Wordpress cache plugin for use with Hiawatha cache.

So far it is going well. I'm aware of the dangers for caching logged in pages etc.
That part is ok.

The problem that I have is that when a admin logs in on the Wordpress site and browses to the home page, Wordpress show an admin bar on the top of the page and some other stuff.
I've handled that when a admin logs in the cache is cleared, however the moment a non logged in user browses the homepage it's getting cached. The moment the admin browses to the homepage it get the page from the cache (the non logged in version).

That is understandable and totally correct.

But is it possible to tell Hiawatha to bypass the cache when a user is logged in?

Nginx solves this problem like this (from nginx config file):
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}

Hiawatha version: 9.2
Operating System: Debian 7 32 Bit
Hugo Leisink
15 October 2013, 09:35
You can't tell Hiawatha to bypass the cache, because the CGI script is not executed when its output is in the cache and being used. Take a look at this picture:
           cache
|
client -- Hiawatha -- CGI

A client connects and sends a request for some CGI script. Hiawatha searches its cache for the corresponding output. If found, the output is taken from the cache and send. If not, the CGI is executed and if the CGI says 'you can cache this', Hiawatha will place a copy in the cache and sends the output to the client. For a CGI to say 'bypass the cache and use my output' the CGI has to be executed first. But the CGI is not executed when its output is already in the cache.
Martijn
15 October 2013, 09:59
Thanks for the explanation, I understand the picture.

But can I place this as a feature request?
Because it would really be helpful if it is possible. A lot of CMS systems today allow the admin or another user to tinker with the frontend stuff directly of the website, and this causes problems with the cache when logged in users and non logged in users browse the same page.

Nginx has a fastcgi_cache_bypass parameter. When set the current url loaded will not be fetched from the CGI cache but like a normal page load without cache.
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}

location ~ .php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;

fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}

http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_bypass

Hugo Leisink
15 October 2013, 10:18
Sure, I'll take a look at it for 9.4. But no promises yet.
Martijn
15 October 2013, 10:48
Tnx!

I would be very happy because the hiawatha x cache is really great.
The plugin I'm making is very simple and the effect is significant on Wordpress.

I get about 20 req/s without x-cache and 2000 req/s with the x-cache header.
Those values are of course very subjective but it is about the difference.

Thanks for making such a awesome webserver.
This topic has been closed.