Feature: #102628 - Cache instruction middleware

See forge#102628

Description

TYPO3 v13 introduces the new frontend-related PSR-7 request attribute frontend.cache.instruction implemented by class \TYPO3\CMS\Frontend\Cache\CacheInstruction. This replaces the previous TyposcriptFrontendController->no_cache property and boolean noCache request attribute.

Impact

The attribute can be used by middlewares to disable cache mechanics of the frontend rendering.

In early middlewares before typo3/cms-frontend/tsfe, the attribute may or may not exist already. A safe way to interact with it is like this:

$cacheInstruction = $request->getAttribute('frontend.cache.instruction', new CacheInstruction());
$cacheInstruction->disableCache('EXT:my-extension: My-reason disables caches.');
$request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction);
Copied!

Extension with middlewares or other code after typo3/cms-frontend/tsfe can assume the attribute to be set already. Usage example:

$cacheInstruction = $request->getAttribute('frontend.cache.instruction');
$cacheInstruction->disableCache('EXT:my-extension: My-reason disables caches.');
Copied!