• Resolved Georgi Tsvetanov

    (@gtsvetanov)


    Hello,

    As you maybe know I’ve made some changes requested in these topics:
    Add Cache key generation hook
    Save accessed URLs for a cache key

    Where I’ve added my changes in pastebin if you wish to add them to the plugin. Today I’ve noticed that OPTIONS requests are not cached at all which is performance issue (for me). I’ve added them with following filter:

    
    add_filter('wp_rest_cache/allowed_request_methods', function($allowedRequestMethods = []) {
    	$allowedRequestMethods[] = 'OPTIONS';
    	
    	$allowedRequestMethods = array_combine(array_values($allowedRequestMethods), array_values($allowedRequestMethods));
    	
    	return $allowedRequestMethods;
    }, 10, 1);
    

    But there is a problem with duplicated cache key with different content. So I’ve added request method in cache key and everything works like a charm.

    I’ve replaced this line:
    $this->cache_key = md5( $this->request_uri . wp_json_encode( $this->request_headers ) . wp_json_encode($cache_key_params) );
    With this:
    $this->cache_key = md5( $_SERVER['REQUEST_METHOD'] . $this->request_uri . wp_json_encode( $this->request_headers ) . wp_json_encode( $cache_key_params ) );

    Original line in latest plugin version is:
    $this->cache_key = md5( $this->request_uri . wp_json_encode( $this->request_headers ) );

    Hope this will help others.

    Best regards,
    Georgi!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘BUG with cache key for different request methods’ is closed to new replies.