Problem
There is no way in MediaWiki to apply actions dependent on whether a page is cacheable or not. The last hook that can be used before output is sent to the client is AfterFinalPageOutput, but as stated in the documentation, this hook is fired before cacheability is determined (i.e. before OutputPage::sendCacheControl()).
Example
In T152462 it was discovered that the cookie should be applied to all non-chacheable requests, however, the cachability of a request has not been determined, so there is no way to determine if a a request should get the cookie, or if adding the cookie is unsafe.
Solution
Add a hook to OutputPage:: sendCacheControl() and ApiMain:: sendCacheHeaders() (and anywhere else the Cache-Control header is set) that will allow the response to be modified with a result of the cacheability (i.e. will this request be cached in Varnish? on the Client? or Neither?)
Alternatively, T194393: Implement standard middleware interface in MediaWiki (PSR-15).