From fc99c24b0996e848d6541fb6f749ac32977825b3 Mon Sep 17 00:00:00 2001 From: cadeyrn Date: Sun, 19 Feb 2012 13:35:46 +0000 Subject: [PATCH] added APC compression git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@507306 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- advanced-cache.php | 26 ++++++++++++++++++++------ readme.txt | 3 ++- wp-ffpc-common.php | 21 ++++++++++++++------- wp-ffpc.php | 20 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/advanced-cache.php b/advanced-cache.php index b94204f..156d968 100644 --- a/advanced-cache.php +++ b/advanced-cache.php @@ -70,16 +70,23 @@ $wp_ffpc_data_key = $wp_ffpc_config['prefix_data'] . $_SERVER['HTTP_HOST'] . $wp global $wp_ffpc_meta_key; $wp_ffpc_meta_key = $wp_ffpc_config['prefix_meta'] . $_SERVER['HTTP_HOST'] . $wp_ffpc_uri; -/* search for valid data entry */ -global $wp_ffpc_data; -$wp_ffpc_data = wp_ffpc_get ( $wp_ffpc_data_key ); - /* search for valid meta entry */ global $wp_ffpc_meta; $wp_ffpc_meta = wp_ffpc_get ( $wp_ffpc_meta_key ); +/* meta is corrupted or empty */ +if ( !$wp_ffpc_meta ) { + wp_ffpc_start(); + return; +} + +/* search for valid data entry */ +global $wp_ffpc_data; +$uncompress = ( isset($wp_ffpc_meta['compressed']) ) ? $wp_ffpc_meta['compressed'] : false; +$wp_ffpc_data = wp_ffpc_get ( $wp_ffpc_data_key , $uncompress ); + /* data is corrupted or empty */ -if ( !$wp_ffpc_data || !$wp_ffpc_meta ) { +if ( !$wp_ffpc_data ) { wp_ffpc_start(); return; } @@ -240,10 +247,17 @@ function wp_ffpc_callback($buffer) { if (!empty ( $post->post_modified_gmt ) ) $wp_ffpc_meta['lastmodified'] = strtotime ( $post->post_modified_gmt ); } + + /* APC compression */ + $compress = ( ($wp_ffpc_config['cache_type'] == 'apc') && $wp_ffpc_config['apc_compress'] ) ? true : false; + $wp_ffpc_meta['compressed'] = $compress; + /* set meta */ wp_ffpc_set ( $wp_ffpc_meta_key, $wp_ffpc_meta ); + /* set data */ - wp_ffpc_set ( $wp_ffpc_data_key, $buffer ); + $data = $buffer; + wp_ffpc_set ( $wp_ffpc_data_key, $data , $compress ); /* vital for nginx version */ header("HTTP/1.1 200 OK"); diff --git a/readme.txt b/readme.txt index 1c5e5a0..df0290b 100644 --- a/readme.txt +++ b/readme.txt @@ -26,7 +26,8 @@ PHP has two extension for communication with a memcached server, named Memcache (1) pingback hostname will always be generated from the accessed domain, otherwise speed would get highly compromised (2) If used in WordPress Network, the configuration will only be available for network admins at the network admin panel, and will be system-wide and will be applied for every blog. -(3) nginx compatility means that if used with PHP Memcache (not Memcached!) extension, the created memcached entries that can be read and served directly from nginx, making the cache insanely fast. If used with APC or Memcached, this feature is not available (no APC module for nginx, compression incompatibility with Memcached), although, naturally, the cache modul is functional and working, but it will be done by PHP instead of nginx. +(3) nginx compatility means that if used with PHP Memcache (not Memcached!) extension, the created memcached entries can be read and served directly from nginx, making the cache insanely fast. +If used with APC or Memcached, this feature is not available (no APC module for nginx, compression incompatibility with Memcached), although, naturally, the cache modul is functional and working, but it will be done by PHP instead of nginx. Short nginx example configuration is generated on the plugin settings page if Memcache is selected as cache type. Some parts were based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper-cache "Hyper Cache") plugin by Satollo (info@satollo.net). diff --git a/wp-ffpc-common.php b/wp-ffpc-common.php index 4a034bd..3ff4e38 100644 --- a/wp-ffpc-common.php +++ b/wp-ffpc-common.php @@ -80,8 +80,10 @@ function wp_ffpc_clear ( $post_id = false ) { global $wp_ffpc_config; global $post; + $post_only = ( $post_id === 'system_flush' ) ? false : $wp_ffpc_config['invalidation_method']; + /* post invalidation enabled */ - if ( $wp_ffpc_config['invalidation_method'] ) + if ( $post_only ) { $path = substr ( get_permalink($post_id) , 7 ); if (empty($path)) @@ -94,7 +96,7 @@ function wp_ffpc_clear ( $post_id = false ) { { /* in case of apc */ case 'apc': - if ( $wp_ffpc_config['invalidation_method'] ) + if ( $post_only ) { apc_delete ( $meta ); apc_delete ( $data ); @@ -110,7 +112,7 @@ function wp_ffpc_clear ( $post_id = false ) { case 'memcache': case 'memcached': global $wp_ffpc_backend; - if ( $wp_ffpc_config['invalidation_method'] ) + if ( $post_only ) { $wp_ffpc_backend->delete( $meta ); $wp_ffpc_backend->delete( $data ); @@ -135,13 +137,15 @@ function wp_ffpc_clear ( $post_id = false ) { * @param &$data store value, passed by reference for speed * */ -function wp_ffpc_set ( &$key, &$data ) { +function wp_ffpc_set ( &$key, &$data, $compress = false ) { global $wp_ffpc_config; switch ($wp_ffpc_config['cache_type']) { case 'apc': /* use apc_store to overwrite data is existed */ + if ( $compress ) + $data = gzdeflate ( $data , 1 ); apc_store( $key , $data , $wp_ffpc_config['expire']); break; case 'memcache': @@ -160,15 +164,18 @@ function wp_ffpc_set ( &$key, &$data ) { * gets cached element by key * * @param &$key: key of needed cache element - * + * */ -function wp_ffpc_get( &$key ) { +function wp_ffpc_get( &$key , $uncompress = false ) { global $wp_ffpc_config; switch ($wp_ffpc_config['cache_type']) { case 'apc': - return apc_fetch($key); + $value = apc_fetch($key); + if ( $uncompress ) + $value = gzinflate ( $value ); + return $value; case 'memcache': case 'memcached': global $wp_ffpc_backend; diff --git a/wp-ffpc.php b/wp-ffpc.php index 46128a1..a84763e 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -384,6 +384,22 @@ location @rewrites { +
+ +
+ +
+ +
+
+ options['apc_compress'],true); ?> /> + + : print_bool( $this->defaults['apc_compress']); ?> +
+ +
+
+

false, 'nocache_single' => false, 'nocache_page' => false, + 'apc_compress' => false, ); $this->defaults = $defaults; @@ -603,8 +620,11 @@ location @rewrites { update_site_option( WP_FFPC_PARAM , $this->options ); + $this->invalidate('system_flush'); + if ( ! $firstrun ) $this->generate_config(); + } /**