• Resolved Mike Badgley

    (@badg0003)


    I have a few JSON requests I’m making and none of them cache. Here are the three calls that I am making:

    /wp-json/wp/v2/posts?_embed=wp%3Aterm%2Cwp%3Afeaturedmedia&per_page=10&page=1&orderBy=date&order=desc&lang=en&_locale=user
    
    /wp-json/wp/v2/topic?_fields=id%2Cname%2Cslug&per_page=100&lang=en&_locale=user
    
    /wp-json/wp/v2/content-region?_fields=id%2Cname%2Cslug&per_page=100&lang=en&_locale=user

    In terms of the response I get, here is the output for the first one:

    Request URL:
    /wp-json/wp/v2/posts?_embed=wp%3Aterm%2Cwp%3Afeaturedmedia&per_page=10&page=1&orderBy=date&order=desc&lang=en&_locale=user
    Request Method: GET
    Status Code: 200 OK
    Access-Control-Allow-Headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type
    Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages, Link
    Allow: GET, POST
    Cache-Control: no-cache, must-revalidate, max-age=0, no-store, private
    ...

    My hunch is this is not working based on the fact I’m getting a no-cache response for Cache-Control. Any insight would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @badg0003

    Thank you for using our plugin!

    I just did a test with your first call on a test machine and is caching just fine. Are you by any chance sending a nonce with your calls? (For authentication?). If so then that is the reason the calls are not being cached. By default we do not cache authorized calls, since the result should be different per user.

    Thread Starter Mike Badgley

    (@badg0003)

    Thanks very much for confirming. Turns out the @wordpress/api-fetch package automatically sets a nonce header, so once I converted this to use native window.fetch it worked perfectly.

    • This reply was modified 11 months, 3 weeks ago by Mike Badgley.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp-json/wp/v2 not caching’ is closed to new replies.