Problem/Motivation
While working on #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method, I noticed it was unfortunately necessary to rebuild the router whenever you imported (i.e. deployed) RestResourceConfig
config entities. This should happen automatically thanks to a ConfigEvents::SAVE
event subscriber.
Worse, you actually even need to call drupal_flush_all_caches()
: just calling $this->container->get('router.builder')->rebuild()
is insufficient! (I have no idea why yet.)
When doing an import through the UI, this means you need to go to /admin/config/development/performance
and click the Clear all caches
button. If a developer forgets this step, then their REST routes won't work.
Proposed resolution
- Routing system:
- Add
http_response
cache tag to all cacheable responses. - Let route rebuilder invalidate the
http_response_
cache tag after every rebuild.
- Add
- REST module:
- Make
RestResourceConfig::post(Save|Delete)
mark the router as needing a rebuild. - Implement a REST config save event subscriber (for the
rest.settings
config) that marks the router as needing a rebuild.
- Make
Together this means that:
- every router rebuild will now invalidate all responses. Cached 404 responses may become 200s, 200s may become 403s, 404s may become 403s, and so on. Hence all cached responses need to be rebuilt.
- whenever
RestResourceConfig
config entities orrest.settings
simple config change, mark the router as needing a rebuild, which will trigger the above.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.