Hi @jaxwtf
Thank you for using our plugin!
There are several possible answers to your question:
1. You say you want it to flush when you save or update, are these endpoints returning (custom) post types (or taxonomies)? If so then possibly the plugin can not detect the correct object type.
The plugin will try to detect the object types of entries in your endpoint, but this detection is not flawless. It will check for the existence of the fields id
and type
and use the type
as the object type (or check for id
and taxonomy
in the case of a taxonomy). If those fields aren’t present it will not be able to detect the object type.
You can however ‘help’ the plugin to detect the correct object type by using the wp_rest_cache/determine_object_type filter
(see the FAQ).
Once the plugin knows the correct object type it will automatically flush the caches upon saving such a object type.
2. If the endpoint isn’t returning (custom) post types (or taxonomies) I would still recommend using the wp_rest_cache/determine_object_type filter
hook to help the plugin detect the object type.
Once you have done that, upon saving or updating you can programmatically flush all caches of a specific object type
Example:
\WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_object_type_caches( 'products' );
This deletes all caches for object type products
.
3. The last option is to (upon saving or updating) programmatically flush all caches of a specific endpoint. So for instance if you want to flush the caches for the endpoint /wp-json/wp/v2/pages
you can do so like this:
\WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_cache_by_endpoint( '/wp-json/wp/v2/pages' );
This function accepts two extra parameters:
1. $strictness
: This defines how strict you want the caches to match, you have three options for this:
'strict'
: Delete caches by an endpoint path matching only this exact same endpoint path (and query params).
'params'
: Delete caches by an endpoint path matching the exact same endpoint path with any query params that might have been used.
'loose'
: Delete caches by an endpoint path matching any cache that was called starting with the endpoint path (ignoring any query params or subpaths following the given path).
2. $force
: Should the caches be deleted ($force = true) or just flushed ($force = false).