added APC compression
git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@507306 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
745643bc47
commit
fc99c24b09
4 changed files with 56 additions and 14 deletions
|
@ -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");
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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':
|
||||
|
@ -162,13 +166,16 @@ function wp_ffpc_set ( &$key, &$data ) {
|
|||
* @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;
|
||||
|
|
20
wp-ffpc.php
20
wp-ffpc.php
|
@ -384,6 +384,22 @@ location @rewrites {
|
|||
|
||||
<? endif; ?>
|
||||
|
||||
<fieldset class="grid50">
|
||||
<legend><?php _e('Settings for APC', WP_FFPC_PARAM); ?></legend>
|
||||
<dl>
|
||||
|
||||
<dt>
|
||||
<label for="apc_compress"><?php _e("Compress entries", WP_FFPC_PARAM); ?></label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="checkbox" name="apc_compress" id="apc_compress" value="1" <?php checked($this->options['apc_compress'],true); ?> />
|
||||
<span class="description"><?php _e('Try to compress APC entries. Requires PHP ZLIB.', WP_FFPC_PARAM); ?></span>
|
||||
<span class="default"><?php _e('Default ', WP_FFPC_PARAM); ?>: <?php $this->print_bool( $this->defaults['apc_compress']); ?></span>
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<p class="clearcolumns"><input class="button-primary" type="submit" name="<?php echo WP_FFPC_PARAM; ?>-save" id="<?php echo WP_FFPC_PARAM; ?>-save" value="Save Changes" /></p>
|
||||
</form>
|
||||
<?php
|
||||
|
@ -509,6 +525,7 @@ location @rewrites {
|
|||
'nocache_archive' => 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();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue