coderedcorp/wagtail-cache

Wagtail before_serve_page hook not triggering with wagtail-cache middleware

mariorossell opened this issue · 2 comments

If you setup wagtail-cache using only the @cache_page decorator and the mixin all hooks trigger appropriately. However if you use the wagtail-cache middleware the before_serve_page hook does not get triggered on a cached page.
This is a problem if you have any type of last minute validation or even a hit-counter on the before_serve_page hook.

Interesting observation. I would think during a cached request/response cycle, none of the hooks should be triggered. However it is curious that the hooks fire using the decorator and not the middleware.

The middleware behavior would be the expected approach - as the cache should be served directly without invoking any other python code outside of the middleware. This is the same behavior as if an upstream cache (e.g. varnish, cloudflare) were serving the page - wagtail would have no knowledge of it.

We could probably add our own hook or Django signal that would fire during a cached response cycle - however that would slow down the cache.

If you have any suggestions for how this should work, please write up a spec or make a PR. Otherwise I'm going to close this for now, since it is working "as designed". Thanks.