Support » Plugin: WP REST Cache » Caching a perticular end point

  • I am totally new to Rest API caching and I want to make sure that I set things up correctly. My issue is that my PWA App manifest file uses the Rest API and loads exceptionally slowly. It is a common issue for PWA manifest files. It’s end point is How do I make sure that your plugin caches this end point while allowing it to continue caching all other Rest API activity. Right now I don’t see any caches being created and Sight Health shows that the Rest API is activated and working properly.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter aakrealtor


    As a follow up, I installed the following code in my wp-rest.php file to identify the end point I want cached. It it is derived from the URL of the end point above:

    * Register the /wp-json/app/v1/pwp-manifest endpoint so it will be cached.
    */function wprc_add_app_manifest_endpoint( $allowed_endpoints ) {
    if ( ! isset( $allowed_endpoints[ ‘app/v1’ ] ) ||
    ! in_array( ‘posts’, $allowed_endpoints[ ‘app/v1’ ] ) ) {
    $allowed_endpoints[ ‘app/v1’ ][] = ‘manifest’;
    return $allowed_endpoints;
    }add_filter( ‘wp_rest_cache/allowed_endpoints’, ‘wprc_add_app_manifest_endpoint’, 10, 1);

    As a result I see the following in the cache of the WP REST Cache plugin:

    Cache Key:

    Request URI:

    Request Headers

    Request Method:

    Object Type:

    2021-10-30 08:48:16

    # Cache Hits

    check mark

    Is this the expected output? The reasons I am asking are as follows:
    (1) The word “null” appears in the line under request headers.
    (2) The object type is reported as “unknown”.
    (3) I tested in GTmetrix and the end point URL is not being reported as loading any quicker.

    Thanks in advance for any clarifications anyone can offer.

    Plugin Author Richard Korthuis


    Hi @aakrealtor

    The results you are seeing in the cache suggest to me that you have applied some other filter ( wp_rest_cache/cacheable_request_headers ). Since if you would have applied the filter wp_rest_cache/allowed_endpoints the Request Headers wouldn’t contain your pwp-manifest endpoint.

    Now looking at your code for the wp_rest_cache/allowed_endpoint filter, I think you made an error there. In the comment you say you register the /wp-json/app/v1/pwp-manifest endpoint, but in the actual code you left out the pwp- part. So I guess you registered the wrong (non-exisiting?) endpoint /wp-json/app/v1/manifest

    The correct code should be:

     * Register the /wp-json/app/v1/pwp-manifest endpoint so it will be cached.
    function wprc_add_app_manifest_endpoint( $allowed_endpoints ) {
    	if ( ! isset( $allowed_endpoints[ 'app/v1' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'app/v1' ] ) ) {
    		$allowed_endpoints[ 'app/v1' ][] = 'pwp-manifest';
    	return $allowed_endpoints;
    add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_app_manifest_endpoint', 10, 1 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.