Title: BUG with cache key for different request methods
Last modified: August 19, 2020

---

# BUG with cache key for different request methods

 *  Resolved [Georgi Tsvetanov](https://wordpress.org/support/users/gtsvetanov/)
 * (@gtsvetanov)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/bug-with-cache-key-for-different-request-methods/)
 * Hello,
 * As you maybe know I’ve made some changes requested in these topics:
    – [Add Cache key generation hook](https://wordpress.org/support/topic/add-cache-key-generation-hook/)–
   [Save accessed URLs for a cache key](https://wordpress.org/support/topic/save-accessed-urls-by-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!
    -  This topic was modified 5 years, 9 months ago by [Georgi Tsvetanov](https://wordpress.org/support/users/gtsvetanov/).
    -  This topic was modified 5 years, 9 months ago by [Georgi Tsvetanov](https://wordpress.org/support/users/gtsvetanov/).
    -  This topic was modified 5 years, 9 months ago by [Georgi Tsvetanov](https://wordpress.org/support/users/gtsvetanov/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/bug-with-cache-key-for-different-request-methods/#post-13342894)
 * Hi [@gtsvetanov](https://wordpress.org/support/users/gtsvetanov/)
 * Thank you for pointing this out. We will be fixing this in our next release.
 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/bug-with-cache-key-for-different-request-methods/#post-13370686)
 * Hi [@gtsvetanov](https://wordpress.org/support/users/gtsvetanov/)
 * We just released a new version of our plugin, which solves this issue.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘BUG with cache key for different request methods’ is closed to new replies.

 * ![](https://ps.w.org/wp-rest-cache/assets/icon-256x256.png?rev=3328849)
 * [WP REST Cache](https://wordpress.org/plugins/wp-rest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-rest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-rest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-rest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-rest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-rest-cache/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/bug-with-cache-key-for-different-request-methods/#post-13370686)
 * Status: resolved