Skip to content

Instantly share code, notes, and snippets.

Last active Dec 16, 2015
What would you like to do?

ESI-style tags for Batcache


In the template add something like:

<nocache callback="time" />

And in batcache

  1. Before saving the HTML in the cache, do a strpos for <nocache , and save true/false in the cache too.
  2. If true, use the kses_hair function and generate an array of positions/callbacks, and store in cache too.
  3. When serving a cached page check for that bool. If false, serve as usual.
  4. If true, use the cached array to generate the blocks, inject and strip all the <nocache... tags.

<nocache> should only be allowed in the templates/plugins. It should be stripped from any user generated content (commments, post content, etc).

More features

<nocache is_user_logged_in callback="time"> <?php time(); ?> </nocache>

Set a nocache tag only for logged in users. Visitors won't execute the callback, and will get what's inise the nocache tag.

<nocache expiration='3600' callback="time" />

Add a different expiration time for that fragment. ie: Twitter widget in a page that doesn't need to refresh too often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment