Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Naur /source/wp-rest-cache/admin/partials/sub-cache-details.php /modified/wp-rest-cache/admin/partials/sub-cache-details.php
- --- /source/wp-rest-cache/admin/partials/sub-cache-details.php 2019-07-12 13:20:22.000000000 +0300
- +++ /modified/wp-rest-cache/admin/partials/sub-cache-details.php 2020-08-18 23:06:58.666943006 +0300
- @@ -91,6 +91,16 @@
- </div>
- </div>
- <?php endif; ?>
- + <?php if ( isset( $wp_rest_cache['data']['uris'] ) ) : ?>
- + <div class="postbox">
- + <h3 class="hndle"><?php esc_html_e( 'Request URIs', 'wp-rest-cache' ); ?></h3>
- + <div class="inside">
- + <?php foreach ( $wp_rest_cache['data']['uris'] as $uri ) : ?>
- + <p><?php echo $uri; ?></p>
- + <?php endforeach; ?>
- + </div>
- + </div>
- + <?php endif; ?>
- <div class="postbox">
- <h3 class="hndle"><?php esc_html_e( 'Cache data', 'wp-rest-cache' ); ?></h3>
- <div class="inside">
- diff -Naur /source/wp-rest-cache/includes/api/class-endpoint-api.php /modified/wp-rest-cache/includes/api/class-endpoint-api.php
- --- /source/wp-rest-cache/includes/api/class-endpoint-api.php 2020-07-02 09:25:52.000000000 +0300
- +++ /modified/wp-rest-cache/includes/api/class-endpoint-api.php 2020-08-18 22:58:42.192442025 +0300
- @@ -167,8 +167,10 @@
- private function build_cache_key() {
- $this->build_request_uri();
- $this->set_cacheable_request_headers();
- -
- - $this->cache_key = md5( $this->request_uri . wp_json_encode( $this->request_headers ) );
- +
- + $cache_key_params = get_option( 'wp_rest_cache_cache_key_params', [] );
- +
- + $this->cache_key = md5( $this->request_uri . wp_json_encode( $this->request_headers ) . wp_json_encode($cache_key_params) );
- }
- /**
- @@ -218,10 +220,11 @@
- * @param array $result Response data to send to the client.
- * @param \WP_REST_Server $server Server instance.
- * @param \WP_REST_Request $request Request used to generate the response.
- + * @param array $uris
- *
- * @return array Response data to send to the client.
- */
- - public function save_cache( $result, \WP_REST_Server $server, \WP_REST_Request $request ) {
- + public function save_cache( $result, \WP_REST_Server $server, \WP_REST_Request $request, $uris = [] ) {
- // Only Avoid cache if not 200.
- if ( ! empty( $result ) && is_array( $result ) && isset( $result['data']['status'] ) && 200 !== (int) $result['data']['status'] ) {
- return $result;
- @@ -233,9 +236,12 @@
- }
- $data = array(
- - 'data' => $result,
- - 'headers' => $this->response_headers,
- + 'data' => $result,
- + 'headers' => $this->response_headers,
- + 'uris' => $uris,
- );
- + $data['uris'][$_SERVER['REQUEST_URI']] = $_SERVER['REQUEST_URI'];
- +
- \WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()->set_cache( $this->cache_key, $data, 'endpoint', $this->request_uri, '', $this->request_headers );
- return $result;
- @@ -340,6 +346,12 @@
- $this->rest_send_cors_headers( '' );
- echo $data; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- +
- + $cache['uris'] = (isset($cache['uris'])) ? $cache['uris'] : [];
- + if (!isset($cache['uris'][$_SERVER['REQUEST_URI']])) {
- + $this->save_cache($cache['data'], new \WP_REST_Server(), $this->request, $cache['uris']);
- + }
- +
- exit;
- }
- }
- @@ -466,6 +478,20 @@
- if ( (int) $original_cache_hit_recording !== (int) $cache_hit_recording ) {
- update_option( 'wp_rest_cache_hit_recording', (int) $cache_hit_recording, true );
- }
- +
- + $original_cache_key_params = get_option( 'wp_rest_cache_cache_key_params', [] );
- + /**
- + * Filter to add custom params in cache key
- + *
- + * Allows to add custom parameters in cache keys. For example if you wish to add the date to each cache key
- + *
- + * @param array $original_cache_key_params An array of existing custom cache key params
- + */
- + $cache_key_params = apply_filters( 'wp_rest_cache/cache_key_params', $original_cache_key_params );
- + if ( $original_cache_key_params !== $cache_key_params ) {
- + ksort($cache_key_params, SORT_NATURAL);
- + update_option( 'wp_rest_cache_cache_key_params', $cache_key_params, true );
- + }
- }
- /**
- diff -Naur /source/wp-rest-cache/includes/caching/class-caching.php /modified/wp-rest-cache/includes/caching/class-caching.php
- --- /source/wp-rest-cache/includes/caching/class-caching.php 2020-07-02 09:25:52.000000000 +0300
- +++ /modified/wp-rest-cache/includes/caching/class-caching.php 2020-08-18 23:16:25.378398843 +0300
- @@ -462,7 +462,9 @@
- // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
- $affected_rows = $wpdb->query( $wpdb->prepare( $sql, date_i18n( 'Y-m-d H:i:s', 0 ) ) );
- -
- +
- + apply_filters('wp_rest_cache/delete_all_caches', $affected_rows);
- +
- if ( 0 !== $affected_rows && false !== $affected_rows ) {
- $this->schedule_cleanup();
- }
- @@ -496,7 +498,9 @@
- // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
- $affected_rows = $wpdb->query( $wpdb->prepare( $sql, date_i18n( 'Y-m-d H:i:s', 0 ), $id, $object_type ) );
- -
- +
- + apply_filters('wp_rest_cache/delete_related_caches', $affected_rows);
- +
- if ( 0 !== $affected_rows && false !== $affected_rows ) {
- $this->schedule_cleanup();
- }
- @@ -519,7 +523,9 @@
- // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
- $affected_rows = $wpdb->query( $wpdb->prepare( $sql, date_i18n( 'Y-m-d H:i:s', 0 ), 'endpoint', $object_type, false ) );
- -
- +
- + apply_filters('wp_rest_cache/delete_object_type_caches', $affected_rows);
- +
- if ( 0 !== $affected_rows && false !== $affected_rows ) {
- $this->schedule_cleanup();
- }
- diff -Naur /source/wp-rest-cache/includes/class-activator.php /modified/wp-rest-cache/includes/class-activator.php
- --- /source/wp-rest-cache/includes/class-activator.php 2020-07-02 09:25:52.000000000 +0300
- +++ /modified/wp-rest-cache/includes/class-activator.php 2020-08-18 22:41:12.178802150 +0300
- @@ -44,6 +44,9 @@
- if ( ! is_null( get_option( 'wp_rest_cache_hit_recording', null ) ) ) {
- add_option( 'wp_rest_cache_hit_recording', 1, '', true );
- }
- + if ( ! get_option( 'wp_rest_cache_cache_key_params' ) ) {
- + add_option( 'wp_rest_cache_cache_key_params', [], '', true );
- + }
- self::create_mu_plugin();
- }
Advertisement
Add Comment
Please, Sign In to add comment