all repos — wp-ffpc @ 180ad0f2bf3446dc77ac7a9bdd95a5ff59141423

bugfix, version v0.2.2

git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@508069 b8457f37-d9ea-0310-8a92-e5e31aec5664
cadeyrn cadeyrn@b8457f37-d9ea-0310-8a92-e5e31aec5664
Tue, 21 Feb 2012 06:39:19 +0000
commit

180ad0f2bf3446dc77ac7a9bdd95a5ff59141423

parent

47f1cf2f8fe61ed382bcb7254fe7e2257038f136

3 files changed, 41 insertions(+), 34 deletions(-)

jump to
M readme.txtreadme.txt

@@ -3,7 +3,7 @@ Contributors: cadeyrn

Tags: cache, APC, memcached, full page cache Requires at least: 3.0 Tested up to: 3.3.1 -Stable tag: 0.2.1 +Stable tag: 0.2.2 Fast Full Page Cache, backend can be memcached or APC

@@ -46,17 +46,20 @@ == Upgrade Notice ==

== Changelog == += 0.2.2 = +2012.02.21 + +* memcache types bugfix, reported in forum, thanks! + = 0.2.1 = 2012.02.21 * bugfix, duplicated inclusion could emerge, fix added, thanks for Géza Kuti for reporting! - = 0.2 = 2012.02.19 * added APC compression option ( requires PHP ZLIB ). Useful is output pages are large. Compression is on lowest level, therefore size/CPU load is more or less optimal. - = 0.1 = 2012.02.16
M wp-ffpc-common.phpwp-ffpc-common.php

@@ -20,18 +20,15 @@ * @param $type [optional] if set, alive will be tested against this

* if false, backend will be globally initiated * when set, backend will not become global, just tested if alive */ -function wp_ffpc_init( $type = false ) { - global $wp_ffpc_config; +function wp_ffpc_init( $wp_ffpc_config ) { + global $wp_ffpc_backend; $wp_ffpc_backend_status = false; - $reg_backend = $type; - // $type is to test an exact backend */ - if ( !$type ) - $type = $wp_ffpc_config['cache_type']; - + if ( empty ( $wp_ffpc_config )) + global $wp_ffpc_config; /* verify selected storage is available */ - switch ($type) + switch ( $wp_ffpc_config['cache_type'] ) { /* in case of apc */ case 'apc':

@@ -49,10 +46,11 @@ case 'memcache':

/* Memcache class does not exist, Memcache extension is not available */ if (!class_exists('Memcache')) return false; - if ($reg_backend) - global $wp_ffpc_backend; - $wp_ffpc_backend = new Memcache(); - $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + if ( $wp_ffpc_backend == NULL ) + { + $wp_ffpc_backend = new Memcache(); + $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + } $wp_ffpc_backend_status = $wp_ffpc_backend->getServerStatus( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); break;

@@ -61,10 +59,11 @@ case 'memcached':

/* Memcached class does not exist, Memcached extension is not available */ if (!class_exists('Memcached')) return false; - if ($reg_backend) - global $wp_ffpc_backend; - $wp_ffpc_backend = new Memcached(); - $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + if ( $wp_ffpc_backend == NULL ) + { + $wp_ffpc_backend = new Memcached(); + $wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); + } $wp_ffpc_backend_status = array_key_exists( $wp_ffpc_config['host'] . ':' . $wp_ffpc_config['port'] , $wp_ffpc_backend->getStats() ); break;

@@ -143,6 +142,7 @@ *

*/ function wp_ffpc_set ( &$key, &$data, $compress = false ) { global $wp_ffpc_config; + global $wp_ffpc_backend; switch ($wp_ffpc_config['cache_type']) {

@@ -150,16 +150,20 @@ case 'apc':

/* use apc_store to overwrite data is existed */ if ( $compress ) $data = gzdeflate ( $data , 1 ); - apc_store( $key , $data , $wp_ffpc_config['expire']); + return apc_store( $key , $data , $wp_ffpc_config['expire']); break; case 'memcache': - global $wp_ffpc_backend; - /* false to disable compression, vital for nginx */ - $wp_ffpc_backend->set ( $key, $data , false, $wp_ffpc_config['expire'] ); + if ( $wp_ffpc_backend != NULL ) + /* false to disable compression, vital for nginx */ + $wp_ffpc_backend->set ( $key, $data , false, $wp_ffpc_config['expire'] ); + else + return false; break; case 'memcached': - global $wp_ffpc_backend; - $wp_ffpc_backend->set ( $key, $data , $wp_ffpc_config['expire'] ); + if ( $wp_ffpc_backend != NULL ) + $wp_ffpc_backend->set ( $key, $data , $wp_ffpc_config['expire'] ); + else + return false; break; } }

@@ -172,6 +176,7 @@ *

*/ function wp_ffpc_get( &$key , $uncompress = false ) { global $wp_ffpc_config; + global $wp_ffpc_backend; switch ($wp_ffpc_config['cache_type']) {

@@ -182,8 +187,10 @@ $value = gzinflate ( $value );

return $value; case 'memcache': case 'memcached': - global $wp_ffpc_backend; - return $wp_ffpc_backend->get($key); + if ( $wp_ffpc_backend != NULL ) + return $wp_ffpc_backend->get($key); + else + return false; default: return false; }
M wp-ffpc.phpwp-ffpc.php

@@ -1,7 +1,7 @@

<?php /* Plugin Name: WP-FFPC -Version: 0.2.1 +Version: 0.2.2 Plugin URI: http://petermolnar.eu/wordpress/wp-ffpc Description: Fast Full Page Cache, backend can be memcached or APC Author: Peter Molnar

@@ -75,7 +75,7 @@ /* register options */

$this->get_options(); /* check is backend is available */ - $alive = wp_ffpc_init( $this->options['cache_type'] ); + $alive = wp_ffpc_init( $this->options ); /* don't register hooks if backend is dead */ if ($alive)

@@ -328,12 +328,9 @@

<div> <strong><?php _e( 'Memcached server status: ', WP_FFPC_PARAM ) ; ?> <?php - if (class_exists('Memcache')) - $server_status = wp_ffpc_init('memcache'); - elseif (class_exists('Memcached')) - $server_status = wp_ffpc_init('memcached'); + $server_status = wp_ffpc_init( $this->options); - $server_status = ( $server_status ) ? '<span class="error-msg">down</span>' : '<span class="ok-msg">up & running</span>' ; + $server_status = ( empty($server_status) || $server_status == 0 ) ? '<span class="error-msg">down</span>' : '<span class="ok-msg">up & running</span>' ; echo $server_status; ?> </strong>