"WordPress cache optimization?"

Date:June 30th, 2014
Comments: 0
  • Join date: 11-30-99
  • Posts: 23
View Counter:
Rate it
  • Your favorite browser?

    View Results

    Loading ... Loading ...
  • bodytext bodytext bodytext

During development of my site i intentionally disabled ANY cache.

I did it because caching is known to cause “artifacts” during development. Hence, my site was slower then in should be.

After implementing some core features, like wordpress and phpbb 3 integration, i decided to enable the cache.

I have just enabled the wordpress default cache.

It is done by adding

define('ENABLE_CACHE', true);

to wp-config.php

The line must be inserted BEFORE:

/* That's all, stop editing! Happy blogging. */
define('ABSPATH', dirname(__FILE__).'/');

Also, i created the writable cache directory under wp-content of my wordpress. It is where wordpress will put the cache.
If you want to check that it works, just load some pages and see if there is something put by wordpress in the directory.

My first impressions:

wordpress cache improved loading of my pages by 30%-70% without any settings or code change. Until now, no problem watsoever with the cache.
I could edit the template and all changes were rendered just fine.

The level of improvement was bettor for frontpage but worse for single entries and articles. But it maybe just how i implemented the templates.
There is a lot of custom code there.

From here i will analize compare other cache implementations for wordpress and optimize standard features, like image loading or css compression…

First Artifacts

After some testing i found out that the DB query is cached and not always updates just after the data have changed.
It might be a hell during development but its “ok” for blogging.

The reason for update delay is, at least in my older wordpress, here:


function &get_pages($args = '') {
	global $wpdb;
	if ( is_array($args) )
		$r = &$args;
		parse_str($args, $r);
	$defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title',
				'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '');
	$r = array_merge($defaults, $r);
	extract($r, EXTR_SKIP);
	$key = md5( serialize( $r ) );
	if ( $cache = wp_cache_get( 'get_pages', 'page' ) )
		if ( isset( $cache[ $key ] ) )
			return apply_filters('get_pages', $cache[ $key ], $r );

So, if the query was executed, say 1 minute ago, result is taken from the cache. If data changes, it is “delayed” for the duration of cache refresh.

if ( $cache = wp_cache_get( 'get_pages', 'page' ) )

For those who code and have no problem tackling with the wordpress source, the get_pages() function will provide great level of control and insight. You can see which queries are posted and what is the outcome.

Be Sociable, Share!
Interesting entry?
VN:F [1.8.5_1061]
Rating: 0 (from 0 votes)
0 votes 'YES'  0 votes 'NO'

No tags for this post.


Be Sociable, Share!



Leave a Reply