bugfix, version v0.2.2

git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@508069 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
cadeyrn 2012-02-21 06:39:19 +00:00
parent 47f1cf2f8f
commit 180ad0f2bf
3 changed files with 41 additions and 34 deletions

View file

@ -3,7 +3,7 @@ Contributors: cadeyrn
Tags: cache, APC, memcached, full page cache Tags: cache, APC, memcached, full page cache
Requires at least: 3.0 Requires at least: 3.0
Tested up to: 3.3.1 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 Fast Full Page Cache, backend can be memcached or APC
@ -46,18 +46,21 @@ Some parts were based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper
== Changelog == == Changelog ==
= 0.2.2 =
2012.02.21
* memcache types bugfix, reported in forum, thanks!
= 0.2.1 = = 0.2.1 =
2012.02.21 2012.02.21
* bugfix, duplicated inclusion could emerge, fix added, thanks for Géza Kuti for reporting! * bugfix, duplicated inclusion could emerge, fix added, thanks for Géza Kuti for reporting!
= 0.2 = = 0.2 =
2012.02.19 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. * 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 = = 0.1 =
2012.02.16 2012.02.16

View file

@ -20,18 +20,15 @@ if ( function_exists('wp_ffpc_init') || function_exists('wp_ffpc_clear') || func
* if false, backend will be globally initiated * if false, backend will be globally initiated
* when set, backend will not become global, just tested if alive * when set, backend will not become global, just tested if alive
*/ */
function wp_ffpc_init( $type = false ) { function wp_ffpc_init( $wp_ffpc_config ) {
global $wp_ffpc_config; global $wp_ffpc_backend;
$wp_ffpc_backend_status = false; $wp_ffpc_backend_status = false;
$reg_backend = $type; if ( empty ( $wp_ffpc_config ))
// $type is to test an exact backend */ global $wp_ffpc_config;
if ( !$type )
$type = $wp_ffpc_config['cache_type'];
/* verify selected storage is available */ /* verify selected storage is available */
switch ($type) switch ( $wp_ffpc_config['cache_type'] )
{ {
/* in case of apc */ /* in case of apc */
case 'apc': case 'apc':
@ -49,10 +46,11 @@ function wp_ffpc_init( $type = false ) {
/* Memcache class does not exist, Memcache extension is not available */ /* Memcache class does not exist, Memcache extension is not available */
if (!class_exists('Memcache')) if (!class_exists('Memcache'))
return false; return false;
if ($reg_backend) if ( $wp_ffpc_backend == NULL )
global $wp_ffpc_backend; {
$wp_ffpc_backend = new Memcache(); $wp_ffpc_backend = new Memcache();
$wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); $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'] ); $wp_ffpc_backend_status = $wp_ffpc_backend->getServerStatus( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] );
break; break;
@ -61,10 +59,11 @@ function wp_ffpc_init( $type = false ) {
/* Memcached class does not exist, Memcached extension is not available */ /* Memcached class does not exist, Memcached extension is not available */
if (!class_exists('Memcached')) if (!class_exists('Memcached'))
return false; return false;
if ($reg_backend) if ( $wp_ffpc_backend == NULL )
global $wp_ffpc_backend; {
$wp_ffpc_backend = new Memcached(); $wp_ffpc_backend = new Memcached();
$wp_ffpc_backend->addServer( $wp_ffpc_config['host'] , $wp_ffpc_config['port'] ); $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() ); $wp_ffpc_backend_status = array_key_exists( $wp_ffpc_config['host'] . ':' . $wp_ffpc_config['port'] , $wp_ffpc_backend->getStats() );
break; break;
@ -143,6 +142,7 @@ function wp_ffpc_clear ( $post_id = false ) {
*/ */
function wp_ffpc_set ( &$key, &$data, $compress = false ) { function wp_ffpc_set ( &$key, &$data, $compress = false ) {
global $wp_ffpc_config; global $wp_ffpc_config;
global $wp_ffpc_backend;
switch ($wp_ffpc_config['cache_type']) switch ($wp_ffpc_config['cache_type'])
{ {
@ -150,16 +150,20 @@ function wp_ffpc_set ( &$key, &$data, $compress = false ) {
/* use apc_store to overwrite data is existed */ /* use apc_store to overwrite data is existed */
if ( $compress ) if ( $compress )
$data = gzdeflate ( $data , 1 ); $data = gzdeflate ( $data , 1 );
apc_store( $key , $data , $wp_ffpc_config['expire']); return apc_store( $key , $data , $wp_ffpc_config['expire']);
break; break;
case 'memcache': case 'memcache':
global $wp_ffpc_backend; if ( $wp_ffpc_backend != NULL )
/* false to disable compression, vital for nginx */ /* false to disable compression, vital for nginx */
$wp_ffpc_backend->set ( $key, $data , false, $wp_ffpc_config['expire'] ); $wp_ffpc_backend->set ( $key, $data , false, $wp_ffpc_config['expire'] );
else
return false;
break; break;
case 'memcached': case 'memcached':
global $wp_ffpc_backend; if ( $wp_ffpc_backend != NULL )
$wp_ffpc_backend->set ( $key, $data , $wp_ffpc_config['expire'] ); $wp_ffpc_backend->set ( $key, $data , $wp_ffpc_config['expire'] );
else
return false;
break; break;
} }
} }
@ -172,6 +176,7 @@ function wp_ffpc_set ( &$key, &$data, $compress = false ) {
*/ */
function wp_ffpc_get( &$key , $uncompress = false ) { function wp_ffpc_get( &$key , $uncompress = false ) {
global $wp_ffpc_config; global $wp_ffpc_config;
global $wp_ffpc_backend;
switch ($wp_ffpc_config['cache_type']) switch ($wp_ffpc_config['cache_type'])
{ {
@ -182,8 +187,10 @@ function wp_ffpc_get( &$key , $uncompress = false ) {
return $value; return $value;
case 'memcache': case 'memcache':
case 'memcached': case 'memcached':
global $wp_ffpc_backend; if ( $wp_ffpc_backend != NULL )
return $wp_ffpc_backend->get($key); return $wp_ffpc_backend->get($key);
else
return false;
default: default:
return false; return false;
} }

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Plugin Name: WP-FFPC Plugin Name: WP-FFPC
Version: 0.2.1 Version: 0.2.2
Plugin URI: http://petermolnar.eu/wordpress/wp-ffpc Plugin URI: http://petermolnar.eu/wordpress/wp-ffpc
Description: Fast Full Page Cache, backend can be memcached or APC Description: Fast Full Page Cache, backend can be memcached or APC
Author: Peter Molnar Author: Peter Molnar
@ -75,7 +75,7 @@ if (!class_exists('WPFFPC')) {
$this->get_options(); $this->get_options();
/* check is backend is available */ /* 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 */ /* don't register hooks if backend is dead */
if ($alive) if ($alive)
@ -328,12 +328,9 @@ if (!class_exists('WPFFPC')) {
<div> <div>
<strong><?php _e( 'Memcached server status: ', WP_FFPC_PARAM ) ; ?> <strong><?php _e( 'Memcached server status: ', WP_FFPC_PARAM ) ; ?>
<?php <?php
if (class_exists('Memcache')) $server_status = wp_ffpc_init( $this->options);
$server_status = wp_ffpc_init('memcache');
elseif (class_exists('Memcached'))
$server_status = wp_ffpc_init('memcached');
$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; echo $server_status;
?> ?>
</strong> </strong>