Hi @gtsvetanov
I understand your issue and have investigated your patch. I see you added a filter wp_rest_cache/cache_key_params
for this. However, I don’t think this will work.
The results of the filter are saved to an option, this is because the caching is done via a must use plugin before other plugins or the theme is loaded. So if we wouldn’t save it as an option but use the filter straight away, it would never be used, since the filters can not have been added yet (unles you use a must use plugin which is loaded before our plugin).
Now let’s assume you hit this endpoint for the first time at at 05:02 AM on 01-Sep-2020. Since there is not yet a cache available the must use plugin can not return a cache, so all code (from other plugins and theme) is executed and the filter is applied, so now your date would be saved to the option field as 2020-09-01
and it would be used for the cache key.
Now we hit the endpoint again at 03:42 AM on 02-Sep-2020. The must use plugin will retrieve the option field and it is set as 2020-09-01
and used for the cache key. It will find a cache for this cache key and return it. No other code is executed, so the option field will not be set to the current date until the old cache expires or a call to WordPress is done which isn’t cached and does trigger the option field update.
So as you can see there is a slightly bigger chance the cache is invalidated a little sooner, but there still isn’t a guarantee it is invalidated immediately on the new day.
I am going to discuss your issue with my colleague and see if we can come up with a working solution without always adding the date to the cache key (since this is only wanted for your specific use case and it should not be default behavior).