Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've read this post here but am unsure where to start. https://www.varnish-cache.org/trac/wiki/ESIfeatures

Edit for clarification: I do want to use Full page caching but once we cache say the article page, it can stay in the cache for a day or so, or if something pushes it out. But I'd Want the sidebar to refresh at a faster rate

share|improve this question
    
Why will you want to do something like that? It will probably not save you the effort of implementing some caching, so you might as well cache full pages instead of partials. –  Mark Kaplun Jan 21 '13 at 17:33
    
Please be more specific on a problem you actual face, WPSE answers are based on solutions. –  Wyck Jan 21 '13 at 18:54
    
Sorry. I do want to use Full page caching but once we cache say the article page, it can stay in the cache for a day or so, or if something pushes it out. But I'd Want the sidebar to refresh at a faster rate –  user26312 Jan 21 '13 at 19:39

1 Answer 1

up vote 0 down vote accepted

You can do something like the following:

If you have a sidebar called "Sidebar"

<?php
if ( !dynamic_sidebar("Sidebar") ) :
endif;
?>

You wrap it in ESI tags, one for if ESI is not enabled and one if it is:

<esi:remove>
  <?php
  if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Sidebar") ) :
  endif;
  ?>
</esi:remove>
<!--esi
<esi:include src="/wp-content/plugins/myplugin/esihandler.php"/>
-->

Then, create the endpoint that ESI will pull from, call it esihandler.php:

<?php
$cwd = getcwd();
$path = substr($cwd, 0, strpos($cwd, 'wp-content/'));
require $path . 'wp-blog-header.php';

if ( !dynamic_sidebar("Sidebar") ) :
endif; 

Finally, update your varnish config for the appropriate cache times in the sub vlc_fetch call:

if (req.url ~ "esihandler.php") {
  set beresp.ttl = 10m;
}
else {
  set beresp.do_esi = true;
  set beresp.ttl = 1440m;
}
share|improve this answer
    
That will work with one sidebar, but what do you do when you have more then one? you probably need to pass the id of the sidebar somehow, maybe as a parameter. –  Mark Kaplun Jan 22 '13 at 23:56
    
Very true. My post was just meant as a starting point –  broderboy Jan 24 '13 at 16:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.