From bc825f4caecaabfabbacd1cab9ef9f9d489fa4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Fri, 22 Aug 2014 15:46:21 +0300 Subject: [PATCH 1/8] Fixed missing braces. --- wp-ffpc-acache.php | 1 + 1 file changed, 1 insertion(+) diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index 904f346..3fff567 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -28,6 +28,7 @@ $wp_ffpc_uri = $_SERVER['REQUEST_URI']; /* no cache for uri with query strings, things usually go bad that way */ if ( isset($wp_ffpc_config['nocache_dyn']) && !empty($wp_ffpc_config['nocache_dyn']) && stripos($wp_ffpc_uri, '?') !== false ) { return false; +} /* no cache for pages starting with /wp- like WP admin */ if (stripos($wp_ffpc_uri, '/wp-') !== false) From 14b1d416d115130c7f48186d9383e598279058f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Fri, 22 Aug 2014 16:41:08 +0300 Subject: [PATCH 2/8] Backported paginated post/page cache clearing. --- wp-ffpc-backend.php | 57 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index 2d03186..0d08149 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -85,6 +85,27 @@ class WP_FFPC_Backend { } + + public static function parse_urimap($uri, $default_urimap=null) { + $uri_parts = parse_url( $uri ); + + $uri_map = array( + '$scheme' => $uri_parts['scheme'], + '$host' => $uri_parts['host'], + '$request_uri' => $uri_parts['path'] + ); + + if (is_array($default_urimap)) { + $uri_map = array_merge($default_urimap, $uri_map); + } + + return $uri_map; + } + + public static function map_urimap($urimap, $subject) { + return str_replace(array_keys($urimap), $urimap, $subject); + } + /*********************** PUBLIC / PROXY FUNCTIONS ***********************/ /** @@ -95,7 +116,7 @@ class WP_FFPC_Backend { */ public function key ( &$prefix ) { /* data is string only with content, meta is not used in nginx */ - $key = $prefix . str_replace ( array_keys( $this->urimap ), $this->urimap, $this->options['key'] ); + $key = $prefix . self::map_urimap($this->urimap, $this->options['key']); $this->log ( sprintf( __translate__( 'original key configuration: %s', $this->plugin_constant ), $this->options['key'] ) ); $this->log ( sprintf( __translate__( 'setting key to: %s', $this->plugin_constant ), $key ) ); return $key; @@ -207,24 +228,36 @@ class WP_FFPC_Backend { if ( !function_exists('get_permalink') ) include_once ( ABSPATH . 'wp-includes/link-template.php' ); - /* get path from permalink */ - $path = substr ( get_permalink( $post_id ) , 7 ); + /* get permalink */ + $permalink = get_permalink( $post_id ); /* no path, don't do anything */ - if ( empty( $path ) ) { + if ( empty( $permalink ) ) { $this->log ( sprintf( __translate__( 'unable to determine path from Post Permalink, post ID: %s', $this->plugin_constant ), $post_id ), LOG_WARNING ); return false; } - if ( isset($_SERVER['HTTPS']) && ( ( strtolower($_SERVER['HTTPS']) == 'on' ) || ( $_SERVER['HTTPS'] == '1' ) ) ) - $protocol = 'https://'; - else - $protocol = 'http://'; + /* + * It is possible that post/page is paginated with + * Wordpress doesn't seem to expose the number of pages via API. + * So let's just count it. + */ + $content_post = get_post( $post_id ); + $content = $content_post->post_content; + $number_of_pages = 1 + (int)preg_match_all('//', $content, $matches); - /* elements to clear - values are keys, faster to process and eliminates duplicates - */ - $to_clear[ $protocol . $path ] = true; + $current_page_id = ''; + do { + /* urimap */ + $urimap = self::parse_urimap($permalink, $this->urimap); + $urimap['$request_uri'] = $urimap['$request_uri'] . ($current_page_id ? $current_page_id . '/' : ''); + + $clear_cache_key = self::map_urimap($urimap, $this->options['key']); + + $to_clear[ $clear_cache_key ] = true; + + $current_page_id = 1+(int)$current_page_id; + } while ($number_of_pages>1 && $current_page_id<=$number_of_pages); } foreach ( $to_clear as $link => $dummy ) { From bdcae2f62f6c2b31f75af525e79409bfdc563733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Fri, 22 Aug 2014 17:27:23 +0300 Subject: [PATCH 3/8] Added new invalidation method: post/page + posts index page. Clears cache for modified post/page. Also clears posts index page if content of type 'post' was changed. --- wp-ffpc-backend.php | 11 +++++++++++ wp-ffpc-class.php | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index 0d08149..5c34d1d 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -221,6 +221,17 @@ class WP_FFPC_Backend { $this->taxonomy_links( $to_clear ); } + /* clear pasts index page if settings requires it */ + if ( $this->options['invalidation_method'] == 3 ) { + $posts_page_id = get_option( 'page_for_posts' ); + $post_type = get_post_type( $post_id ); + + if ($post_type === 'post' && $posts_page_id != $post_id) { + $this->clear($posts_page_id, $force); + } + } + + /* if there's a post id pushed, it needs to be invalidated in all cases */ if ( !empty ( $post_id ) ) { diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index 2e0b6e6..e66ce88 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -140,6 +140,7 @@ class WP_FFPC extends PluginAbstract { 0 => __( 'flush cache' , $this->plugin_constant ), 1 => __( 'only modified post' , $this->plugin_constant ), 2 => __( 'modified post and all taxonomies' , $this->plugin_constant ), + 3 => __( 'modified post and posts index page' , $this->plugin_constant ), ); /* map of possible key masks */ @@ -483,7 +484,20 @@ class WP_FFPC extends PluginAbstract { -
  • flush cache - clears everything in storage, including values set by other applications
  • only modified post - clear only the modified posts entry, everything else remains in cache
  • modified post and all taxonomies - removes all taxonomy term cache ( categories, tags, home, etc ) and the modified post as well
  • ', $this->plugin_constant); ?>
    +
    plugin_constant); ?> +
      + including values set by other applications', + 'clear only the modified posts entry, everything else remains in cache', + 'removes all taxonomy term cache ( categories, tags, home, etc ) and the modified post as well
      Caution! Slows down page/post saving when there are many tags.', + 'clear cache for modified post and posts index page' + ); + foreach ($this->select_invalidation_method AS $current_key => $current_invalidation_method) { + printf('
    1. %1$s - %2$s
    2. ', $current_invalidation_method, $invalidation_method_description[$current_key]); + } ?> +
    +
    From 304393e66a75f75aa31b4f5de19e2612f5146e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Fri, 22 Aug 2014 17:48:49 +0300 Subject: [PATCH 4/8] Added hook to customise clearing array externally. --- wp-ffpc-backend.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index 5c34d1d..55c5441 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -271,6 +271,9 @@ class WP_FFPC_Backend { } while ($number_of_pages>1 && $current_page_id<=$number_of_pages); } + /* Hook to customise clearing array. */ + apply_filters('wp_ffpc_to_clear_array', $to_clear, $post_id); + foreach ( $to_clear as $link => $dummy ) { /* clear all feeds as well */ $to_clear[ $link. 'feed' ] = true; From 77d94b25c9f7d6483e7b7885e51bf12698dbc30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Mon, 25 Aug 2014 16:58:23 +0300 Subject: [PATCH 5/8] Fixed filter hook. --- wp-ffpc-backend.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index 55c5441..152e19a 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -271,8 +271,8 @@ class WP_FFPC_Backend { } while ($number_of_pages>1 && $current_page_id<=$number_of_pages); } - /* Hook to customise clearing array. */ - apply_filters('wp_ffpc_to_clear_array', $to_clear, $post_id); + /* Hook to custom clearing array. */ + $to_clear = apply_filters('wp_ffpc_to_clear_array', $to_clear, $post_id); foreach ( $to_clear as $link => $dummy ) { /* clear all feeds as well */ From ab5951ebd83756c1ad8d2e8498b00007a227f5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Thu, 4 Sep 2014 14:14:51 +0300 Subject: [PATCH 6/8] Revert "Fixed missing braces." This reverts commit bc825f4caecaabfabbacd1cab9ef9f9d489fa4fb. --- wp-ffpc-acache.php | 1 - 1 file changed, 1 deletion(-) diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index c3db0ed..b93f434 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -28,7 +28,6 @@ $wp_ffpc_uri = $_SERVER['REQUEST_URI']; /* no cache for uri with query strings, things usually go bad that way */ if ( isset($wp_ffpc_config['nocache_dyn']) && !empty($wp_ffpc_config['nocache_dyn']) && stripos($wp_ffpc_uri, '?') !== false ) return false; -} /* no cache for pages starting with /wp- like WP admin */ if (stripos($wp_ffpc_uri, '/wp-') !== false) From 07dde1e13719ea2e0941a404178f7d20afe9fee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Thu, 4 Sep 2014 14:19:24 +0300 Subject: [PATCH 7/8] Merge --- wp-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-common b/wp-common index d8ed40a..d84ff21 160000 --- a/wp-common +++ b/wp-common @@ -1 +1 @@ -Subproject commit d8ed40adaae8be884a4dd14e5744183f4d183640 +Subproject commit d84ff213cd944c22a6a440d6faba502abd1da774 From b1d869adc04c1add42ec5fda6c6a8d2c4e1d3720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Peles=CC=8Cev?= Date: Thu, 4 Sep 2014 14:30:27 +0300 Subject: [PATCH 8/8] Fix merge. --- wp-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-common b/wp-common index d84ff21..d8ed40a 160000 --- a/wp-common +++ b/wp-common @@ -1 +1 @@ -Subproject commit d84ff213cd944c22a6a440d6faba502abd1da774 +Subproject commit d8ed40adaae8be884a4dd14e5744183f4d183640