WordPress.org

Plugin Directory

Changeset 1400627 for memcached


Ignore:
Timestamp:
04/20/16 17:48:19 (17 months ago)
Author:
andy
Message:

memcached: 3.0.0 to make flush work (finally)

Location:
memcached
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • memcached/tags/3.0.0/object-cache.php

    r1394450 r1400627  
    44Plugin Name: Memcached 
    55Description: Memcached backend for the WP Object Cache. 
    6 Version: 2.0.6 
     6Version: 3.0.0 
    77Plugin URI: http://wordpress.org/extend/plugins/memcached/ 
    8 Author: Ryan Boren, Denis de Bernardy, Matt Martz 
     8Author: Ryan Boren, Denis de Bernardy, Matt Martz, Andy Skelton 
    99 
    1010Install this file to wp-content/object-cache.php 
     
    9898 
    9999class WP_Object_Cache { 
    100     var $global_groups = array(); 
     100    var $global_groups = array( 'WP_Object_Cache_global' ); 
    101101 
    102102    var $no_mc_groups = array(); 
     
    106106    var $stats = array(); 
    107107    var $group_ops = array(); 
     108    var $flush_number = array(); 
     109    var $global_flush_number = null; 
    108110 
    109111    var $cache_enabled = true; 
     
    194196 
    195197    function flush() { 
     198        // Do not use the memcached flush method. It acts on an 
     199        // entire memcached server, affecting all sites. 
     200        // Flush is also unusable in some setups, e.g. twemproxy. 
     201        // Instead, rotate the key prefix for the current site. 
     202        // Global keys are rotated when flushing on the main site. 
    196203        $this->cache = array(); 
    197  
    198         // Don't flush if multi-blog. 
    199         if ( function_exists('is_site_admin') || defined('CUSTOM_USER_TABLE') && defined('CUSTOM_USER_META_TABLE') ) 
    200             return true; 
    201  
    202         $ret = true; 
    203         foreach ( array_keys($this->mc) as $group ) 
    204             $ret &= $this->mc[$group]->flush(); 
    205         return $ret; 
     204        $this->rotate_site_keys(); 
     205        if ( is_main_site() ) 
     206            $this->rotate_global_keys(); 
     207    } 
     208 
     209    function rotate_site_keys() { 
     210        $this->add( 'flush_number', intval(microtime(true) * 1e6), 'WP_Object_Cache' ); 
     211        $this->flush_number[ $this->blog_prefix ] = $this->incr( 'flush_number', 1, 'WP_Object_Cache' ); 
     212    } 
     213 
     214    function rotate_global_keys() { 
     215        $this->add( 'flush_number', intval(microtime(true) * 1e6), 'WP_Object_Cache_global' ); 
     216        $this->global_flush_number = $this->incr( 'flush_number', 1, 'WP_Object_Cache_global' ); 
    206217    } 
    207218 
     
    268279    } 
    269280 
     281    function flush_prefix( $group ) { 
     282        if ( $group === 'WP_Object_Cache' || $group === 'WP_Object_Cache_global' ) { 
     283            // Never flush the flush numbers. 
     284            $number = '_'; 
     285        } elseif ( false !== array_search($group, $this->global_groups) ) { 
     286            if ( ! isset( $this->global_flush_number ) ) 
     287                $this->global_flush_number = intval( $this->get('flush_number', 'WP_Object_Cache_global') ); 
     288            if ( $this->global_flush_number === 0 ) 
     289                $this->rotate_global_keys(); 
     290            $number = $this->global_flush_number; 
     291        } else { 
     292            if ( ! isset( $this->flush_number[ $this->blog_prefix ] ) ) 
     293                $this->flush_number[ $this->blog_prefix ] = intval( $this->get('flush_number', 'WP_Object_Cache') ); 
     294            if ( $this->flush_number[ $this->blog_prefix ] === 0 ) 
     295                $this->rotate_site_keys(); 
     296            $number = $this->flush_number[ $this->blog_prefix ]; 
     297        } 
     298        return $number . ':'; 
     299    } 
     300 
    270301    function key($key, $group) { 
    271302        if ( empty($group) ) 
     
    273304 
    274305        $prefix = $this->key_salt; 
     306 
     307        $prefix .= $this->flush_prefix( $group ); 
    275308 
    276309        if ( false !== array_search($group, $this->global_groups) ) 
     
    279312            $prefix .= $this->blog_prefix; 
    280313 
    281         return preg_replace('/\s+/', '', "$prefix$group:$key"); 
     314        return preg_replace('/\s+/', '', "$prefix:$group:$key"); 
    282315    } 
    283316 
     
    413446        if ( function_exists( 'is_multisite' ) ) { 
    414447            $this->global_prefix = ( is_multisite() || defined('CUSTOM_USER_TABLE') && defined('CUSTOM_USER_META_TABLE') ) ? '' : $table_prefix; 
    415             $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':'; 
     448            $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ); 
    416449        } 
    417450 
  • memcached/tags/3.0.0/readme.txt

    r1393336 r1400627  
    44Requires at least: 3.0 
    55Tested up to: 4.5 
    6 Stable tag: 2.0.6 
     6Stable tag: 3.0.0 
    77 
    88Use memcached and the PECL memcache extension to provide a backing store for the WordPress object cache. 
     
    7575== Changelog == 
    7676 
     77= 3.0.0 = 
     78* Flush site cache by rotating keys 
     79* Flush global cache when flushing main site 
     80 
    7781= 2.0.6 = 
    7882* Flush the local cache on wp_cache_flush() 
  • memcached/trunk/object-cache.php

    r1394450 r1400627  
    44Plugin Name: Memcached 
    55Description: Memcached backend for the WP Object Cache. 
    6 Version: 2.0.6 
     6Version: 3.0.0 
    77Plugin URI: http://wordpress.org/extend/plugins/memcached/ 
    8 Author: Ryan Boren, Denis de Bernardy, Matt Martz 
     8Author: Ryan Boren, Denis de Bernardy, Matt Martz, Andy Skelton 
    99 
    1010Install this file to wp-content/object-cache.php 
     
    9898 
    9999class WP_Object_Cache { 
    100     var $global_groups = array(); 
     100    var $global_groups = array( 'WP_Object_Cache_global' ); 
    101101 
    102102    var $no_mc_groups = array(); 
     
    106106    var $stats = array(); 
    107107    var $group_ops = array(); 
     108    var $flush_number = array(); 
     109    var $global_flush_number = null; 
    108110 
    109111    var $cache_enabled = true; 
     
    194196 
    195197    function flush() { 
     198        // Do not use the memcached flush method. It acts on an 
     199        // entire memcached server, affecting all sites. 
     200        // Flush is also unusable in some setups, e.g. twemproxy. 
     201        // Instead, rotate the key prefix for the current site. 
     202        // Global keys are rotated when flushing on the main site. 
    196203        $this->cache = array(); 
    197  
    198         // Don't flush if multi-blog. 
    199         if ( function_exists('is_site_admin') || defined('CUSTOM_USER_TABLE') && defined('CUSTOM_USER_META_TABLE') ) 
    200             return true; 
    201  
    202         $ret = true; 
    203         foreach ( array_keys($this->mc) as $group ) 
    204             $ret &= $this->mc[$group]->flush(); 
    205         return $ret; 
     204        $this->rotate_site_keys(); 
     205        if ( is_main_site() ) 
     206            $this->rotate_global_keys(); 
     207    } 
     208 
     209    function rotate_site_keys() { 
     210        $this->add( 'flush_number', intval(microtime(true) * 1e6), 'WP_Object_Cache' ); 
     211        $this->flush_number[ $this->blog_prefix ] = $this->incr( 'flush_number', 1, 'WP_Object_Cache' ); 
     212    } 
     213 
     214    function rotate_global_keys() { 
     215        $this->add( 'flush_number', intval(microtime(true) * 1e6), 'WP_Object_Cache_global' ); 
     216        $this->global_flush_number = $this->incr( 'flush_number', 1, 'WP_Object_Cache_global' ); 
    206217    } 
    207218 
     
    268279    } 
    269280 
     281    function flush_prefix( $group ) { 
     282        if ( $group === 'WP_Object_Cache' || $group === 'WP_Object_Cache_global' ) { 
     283            // Never flush the flush numbers. 
     284            $number = '_'; 
     285        } elseif ( false !== array_search($group, $this->global_groups) ) { 
     286            if ( ! isset( $this->global_flush_number ) ) 
     287                $this->global_flush_number = intval( $this->get('flush_number', 'WP_Object_Cache_global') ); 
     288            if ( $this->global_flush_number === 0 ) 
     289                $this->rotate_global_keys(); 
     290            $number = $this->global_flush_number; 
     291        } else { 
     292            if ( ! isset( $this->flush_number[ $this->blog_prefix ] ) ) 
     293                $this->flush_number[ $this->blog_prefix ] = intval( $this->get('flush_number', 'WP_Object_Cache') ); 
     294            if ( $this->flush_number[ $this->blog_prefix ] === 0 ) 
     295                $this->rotate_site_keys(); 
     296            $number = $this->flush_number[ $this->blog_prefix ]; 
     297        } 
     298        return $number . ':'; 
     299    } 
     300 
    270301    function key($key, $group) { 
    271302        if ( empty($group) ) 
     
    273304 
    274305        $prefix = $this->key_salt; 
     306 
     307        $prefix .= $this->flush_prefix( $group ); 
    275308 
    276309        if ( false !== array_search($group, $this->global_groups) ) 
     
    279312            $prefix .= $this->blog_prefix; 
    280313 
    281         return preg_replace('/\s+/', '', "$prefix$group:$key"); 
     314        return preg_replace('/\s+/', '', "$prefix:$group:$key"); 
    282315    } 
    283316 
     
    413446        if ( function_exists( 'is_multisite' ) ) { 
    414447            $this->global_prefix = ( is_multisite() || defined('CUSTOM_USER_TABLE') && defined('CUSTOM_USER_META_TABLE') ) ? '' : $table_prefix; 
    415             $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':'; 
     448            $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ); 
    416449        } 
    417450 
  • memcached/trunk/readme.txt

    r1393336 r1400627  
    44Requires at least: 3.0 
    55Tested up to: 4.5 
    6 Stable tag: 2.0.6 
     6Stable tag: 3.0.0 
    77 
    88Use memcached and the PECL memcache extension to provide a backing store for the WordPress object cache. 
     
    7575== Changelog == 
    7676 
     77= 3.0.0 = 
     78* Flush site cache by rotating keys 
     79* Flush global cache when flushing main site 
     80 
    7781= 2.0.6 = 
    7882* Flush the local cache on wp_cache_flush() 
Note: See TracChangeset for help on using the changeset viewer.