| @@ -27,8 +27,23 @@ | ||
| 27 | 27 | // add_action( 'wp_update_nav_menu', [ $this, 'purge_home_cache' ], 10, 2 ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | + * FastCGI cache purge url. | |
| 32 | + * | |
| 33 | + * @return string | |
| 34 | + */ | |
| 35 | + public function purge_cache_url() { | |
| 36 | + return wp_nonce_url( | |
| 37 | + add_query_arg( | |
| 38 | + [ 'flywp-action' => 'purge-fastcgi-cache' ], | |
| 39 | + admin_url( 'index.php?page=flywp' ) | |
| 40 | + ), | |
| 41 | + 'fly-fastcgi-purge-cache' | |
| 42 | + ); | |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 31 | 46 | * Check if the cache is enabled. |
| 32 | 47 | * |
| 33 | 48 | * @return bool |
| 34 | 49 | */ |
| @@ -104,8 +119,13 @@ | ||
| 104 | 119 | */ |
| 105 | 120 | public function purge_cache_by_url( $url ) { |
| 106 | 121 | $parsed = wp_parse_url( $url ); |
| 107 | 122 | $path = isset( $parsed['path'] ) ? $parsed['path'] : ''; |
| 123 | + | |
| 124 | + // Ensure path ends with trailing slash | |
| 125 | + if ( substr( $path, -1 ) !== '/' ) { | |
| 126 | + $path .= '/'; | |
| 127 | + } | |
| 108 | 128 | |
| 109 | 129 | // cache key format (without space): $protocal $method $host $path |
| 110 | 130 | // because of nginx-proxy, all request will be http, so we don't need to check protocal |
| 111 | 131 | // $method is always GET as we only cache GET request |