4 ms·
My site has a lot of dynamic content, so complete page caching doesn't help, nor does query caching or widget caching, so I had to figure out an alternative to
by csulok 16y ago
My site has a lot of dynamic content, so complete page caching doesn't help, nor does query caching or widget caching, so I had to figure out an alternative to all of this.
I installed X-Cache on the server to use as an opcode/bytecode cache (20% speedup) and to use as an extension of WP Cache's object cache mechanism. The latter I found to be immensely powerful.
I just surround ANY section of code in the template file (for example a menu) with the following snippet. This way I reduced page generation times from 350-500ms to 50ms.
<?php
if (false === ($top-menu = wp_cache_get('top-menu','menus'))) {
ob_start();
?>
<?php
$top-menu = ob_get_contents();
ob_end_clean();
wp_cache_set('top-menu', $top-menu, 'menus', 86400);
}
echo $top-menu;
?>
- ryanpetrich 16y agoThe ob_ family of functions are one of PHP's hidden gems.