Forum

Disable X-Hiawatha-Cache serving if visitor has certain cookie(s)

JGM

16 July 2016, 01:55

Hi, first of all thanks for this great web server, have been using it for years now!

I wrote a basic content management system that has a built-in caching mechanism and wrote for it a module [github.com] that sets the X-Hiawatha-Cache each time a page is cached. The performance increase after caching with X-Hiawatha-Cache is amazing!

The only issue I have is that if a user login the pages will still be served from the hiawatha cache. So I don't know if it would be possible to add an option to hiawatha to skip cached pages if the visitor has certain cookies set. In PHP case lets say I send the PHPSESSID to the visitor, when the visitor sends a request back to hiawatha it could parse the cookies and if the cookie PHPSESSID is set then skip the cache and do normal processing. Something like:

CacheSkipCookie = "phpsessid", "other_cookie", "etc..."

So when any of those cookies is detected on client request, then cache is skipped and content served normally. An option like that could work globally and per vhost.

JGM

19 July 2016, 04:16

I noticed some other users also requested a similar feature, and saw some comments that hiawatha caching was designed to be handled by the application. The problem is that many dynamic systems, once a user is logged have to display new elements like edit buttons, admin menu bar, etc... on pages which where cached for guest visitors, but hiawatha doesn't provides a way to decide if cached version of a page shouldn't be used. So this is why I think hiawatha needs this feature, so when a cookie is set the caching mechanism is skipped and the content that is generated for the specific logged user is displayed.

Varnish cache has this feature by default and every page request from client that has cookies isn't retrieved from varnish cache and instead redirerected directly to the webserver. Hiawatha can go a step further and allow you to specify which cookies if set should tell the server to skip the caching system. This way the need for software like varnish becomes irrelevant.

Hugo Leisink

19 July 2016, 08:17

I have implemented such feature, only requires some proper testing. Will be available in the next release. Don't know what that will be, I will be leaving for a 2 weeks holiday tomorrow.

JGM

19 July 2016, 18:24

Hi Hugo, this is great news, thanks a lot for your hard work! Is there a place where I can get current sources with this change to give it a test? I would report back if I find any issues

Hugo Leisink

19 July 2016, 19:05

I will send you a test version after my holiday. Send me an e-mail and I will reply with the beta source code.

JGM

19 July 2016, 19:17

Nice! I just send an email using the contact form on this site , looking forward for some testing!