• Resolved r0cc4t0

    (@r0cc4t0)


    Hello,

    I used $cacheable_headers to add Cache-Control header on a specific route, but the value is null. Any suggestions for changing the value?

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

    (@rockfire)

    Hi @r0cc4t0

    How did you add the Cache-Control header exactly? Because I just tested this on my local test environment and it worked fine when I did it like this:

    function wprc_add_cacheable_request_headers( $cacheable_headers ) {
    	$cacheable_headers['wp/v2/posts'] = 'Cache-Control';
    	return $cacheable_headers;
    }
    add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_cacheable_request_headers', 10, 1);
    Thread Starter r0cc4t0

    (@r0cc4t0)

    Hi @rockfire

    I used this code:

    function wprc_add_postmeta_cache_control( $cacheable_headers ) {
    	$cacheable_headers['custom/v1/post_meta'] = 'Cache-Control';
    	return $cacheable_headers;
    }
    add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_postmeta_cache_control', 10, 1);

    I would like to know how I can modify the content, e.g., {“Cache-Control”:null} to {“Cache-Control”:”max-age=604800″}

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @r0cc4t0

    That code should be enough, if the header is null then I think WordPress isn’t receiving the header at all.

    Thread Starter r0cc4t0

    (@r0cc4t0)

    Hi @rockfire

    Could I modify the value of this header with wp_rest_cache/cache_headers?

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @r0cc4t0

    Yes you could modify it with that filter, but if WordPress isn’t receiving the header I don’t knwo how you would want to modify it to the correct value?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Set Cache-Control value for a specific route’ is closed to new replies.