I am not sure this is even supposed to happen, but it looks like Drupal is caching REST API responses. I have created a module that makes certain data available through the REST API, and changing the value in the DB requires clearing the cache for it to be reflected immediately in the API response.
Is there a way to prevent Drupal from doing this? The idea behind my API responses is that they are supposed to return real-time data. Currently I'm talking about the user.data
service (users_data
table), but an answer for any arbitrary data would be appreciated.
A specific random example of what retrieving the data looks like:
$user_data = \Drupal::service('user.data')->get('my_module', $id);
It looks like the cache I want to avoid is stored in cache_dynamic_page_cache
.
EDIT: The simplest API response in this case (in the get()
method) is:
return new ResourceResponse($user_data);