Invalidate cache on a REST endpoint I have an endpoint that returns an array of Order entities, but it's caching the results so when a new order is placed the cache has to be cleared.

The code within the endpoint is:

// Tried this also.
// $this-&gt;orderManager-&gt;resetCache()
$orders = $this-&gt;orderManager-&gt;loadByProperties([
  'uid' =&gt; $this-&gt;customer-&gt;id(),
]);
$response = new ResourceResponse($orders);
// maybe this doesn't work because it's an \Drupal\Entity\commerce\Order[]
$response-&gt;addCacheableDependency($orders);

return new ResourceResponse($orders);


What am I missing?
See the comment from @Clive, you can only add single objects as dependency. But you need to add a list tag as well, because the entity query may change because of entities added or modified that are not in the cached list.

$list_tags = \Drupal::entityTypeManager()-&gt;getDefinition('entity_type')-&gt;getListCacheTags();
$response-&gt;getCacheableMetadata()-&gt;addCacheTags($list_tags);