Hi @hesselmid
Thank you for using our plugin!
You are correct that our plugin needs id and type/taxonomy. Those fields are needed to correctly determine the object type of the items in the cache record. Now when the object type is determined correctly (i.e. Object type is not Unknown), when a post is updated, our plugin should automatically only flush caches related to that post. So the cache record of the updated post and all other cache records that have a link with the updated post (i.e. an overview call to /wp-json/wp/v2/posts which includes that post).
So if you are saying all caches for that post type are flushed it would mean something isn’t working correctly. Could you check if the object type is determined correctly? You can check by finding the cache record through Settings > WP REST Cache > Endpoint API Caches and see what is in the column “Object Type”
Hi Richard,
Thanks for your quick response!
The object type is determined correctly as “post” for these request URL’s:
/wp-json/wp/v2/posts?slug=${params.slug}&_fields=id,date,type,title,content,yoast_head_json,_links,_embedded&_embed
I’m using a pretty clean WordPress installation without a lot of plugins. I use ACF, but not on posts.
I just removed the plugin and reinstalled it. I visited some posts on the front end and confirmed they where cached correctly with a default expiry date of 1 yr. Then I clicked “Update” on one of the cached posts and all expiry dates changed to “Flushed”.
Do you have any further ideas I could look at?
Hi @hesselmid
It has to do with the slug parameter you are using. As the documentation states:
Limit result set to posts with one or more specific slugs.
https://developer.ww.wp.xz.cn/rest-api/reference/posts/#arguments
so using this parameter the endpoint could return one or more posts. Even when you only supply one slug, WordPress still returns an array of posts. This array causes our plugin to determine this response as being a non-singular result set and therefore it is flushed if any post is added/updated.
For now you could use our wp_rest_cache/is_single_item filter to tell our plugin to not treat is as a singular result set. The following parameters are provided with this filter:
@param boolean $is_single Whether the cache contains a single item (true) or a collection of items (false)
@param mixed $data The data that is to be cached
@param string $uri The requested URI
I am adding this to a list of possible improvements, since we could detect the fact that a single slug is provided and therefore we could treat it as a singular result set.
Ahh, of course!
So the other way would be to first fetch the post id and then use /wp-json/wp/v2/posts/${id}?
Yes, if you would fetch it using the post id it would be detected as a singular result set and all would work just as expected.