I'm working on fixing a custom module that returns XML from a certain route. Essentially what is described in the answers of this question.
Currently this route isn't being cached. I've tried to switch to using CacheableResponse
and setting cache tags but received the error "The controller result claims to be providing relevant cache metadata, but leaked metadata was detected"
At this point I feel a bit lost. How can I adjust caching for this route so it's cached until the returned XML changes?
Here's my current response:
/**
* Class CustomEntityFeedController.
*
* @package Drupal\my_module\Controller
*/
class CustomEntityFeedController extends ControllerBase {
public function feed() {
// Query for custom entities, loop through them, and build XML output.
$xml = $xml_content_header . $xml_content . $xml_content_footer;
$response = new Response();
$response->headers->set('Content-Type', 'xml');
$response->setContent($xml);
}
}
feed
method to return the XML markup. The XML should generally only change if the queried entities are added/removed.