Problem/Motivation
The Viewer submodule's response cache hardcodes the three core download routes in EpubResponseCacheSubscriber::CACHED_ROUTES. Modules that add their own download routes on top of the generator (e.g. epub_generator_localgov_publications) cannot opt in, so their downloads are regenerated on every request. Route extensibility alone is insufficient: a third-party route also needs to enrich the invalidation tags (e.g. an outline-level tag when the route parameter is not the outline root), or its cached entries go stale.
Proposed resolution
Add two alter hooks: hook_epub_generator_viewer_cached_routes_alter(array &$routes) to extend the cached route list, and hook_epub_generator_viewer_cache_tags_alter(array &$tags, array $context) to adjust invalidation tags per entry, with the request and resolved source entity in $context. Document both in a new epub_generator_viewer.api.php, including the requirement that added routes use a {node} or {entity_type}/{entity_id} parameter so the subscriber can resolve the source (unresolvable sources are never cached, by design).
Remaining tasks
Review; kernel test covering an altered-in route (hit, miss, and tag invalidation). epub_generator_localgov_publications adopts the hooks once released.
User interface changes
None.
API changes
Two new alter hooks; EpubResponseCacheSubscriber gains a module_handler constructor argument (internal service, no BC concern).
Data model changes
None.
Issue fork epub_generator-3612025
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
andileco commented