I might be wrong, but there doesnt seem to be an (obvious) way to disable the page cache for a specific page without also losing the dynamic page cache. I know I can trigger the kill switch with:
\Drupal::service("page_cache_kill_switch")->trigger();
But AFAICT this disables any caching completely. If I followed the source code correctly, it seems this sets the Request Policy to "DENY" which is subsequently evaluate by the page cache and dynamic page cache at the same time. Theres no way to differentiate between the two.
Would be really nice (and IMHO way more logical) if the above switch only killed the page_cache - not the dynamic cache. For the latter, there should be: \Drupal::service("dynamic_page_cache_kill_switch")->trigger();
Comments
Comment #7
dpagini CreditAttribution: dpagini as a volunteer commentedAlso interested in this functionality.
Comment #8
hanoiiI stumbled upon this question by looking for something similar.
In my case I needed to disable page cache for a specific request URI but allow dynamic cache to work also for anonymous users.
What I did was setup my own PageCache request policy and simply denying it for that URL.
Also, if you look at how page_cache_kill_switch is implemented:
It's adding itself to both caches, so you could potentially define your own PageCache kill switch that only targets page_cache and that will also work.
Comment #9
apadernoDrupal 8.9.x is now open only to security issues.