Issue Bug New Quiet

#72703Flash message caching has changed in TYPO3 7.3

Felix Nagel 01/14/16, 15:58 updated 11/02/26, 14:54

Description

Flash messages rendered by EXT:fluid VH are cached and rendered from cache on page access. This was not the case before TYPO3 7.3 and is not the case when using TYPO3 6.2.

Example
User creates an object, a flash message is added and the user is redirected to the list view.
The flash message will be cached and displayed to any user until the cache of the page is flushed somehow.

Previously the page cache was disabled whenever the flash messages VH was used within a cached plugin.

Cause of this is a removed no cache config in the flash message VH, see marked line:

https://github.com/TYPO3/TYPO3.CMS/commit/70a7ed3a9a8e4462618c81a47122d6825ab7d70f#diff-c458c84cec13de48e7fabedab0c4e47aL114

This behavior change is undocumented and should be considered breaking.

Links

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch

Commit message
[BUGFIX] Flash message caching has changed in TYPO3 7.3 Resolves: #72703 Releases: main

History 11

  1. Riccardo De Contardi commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2016-05-14T15:57:26+00:00" > 05/14/16, 15:57 </span>

    Hi. does this issue still occur in 7.6.6 or the latest master? Thank you!

  2. Felix Nagel commented <span data-processor="relativetime" data-value="2016-05-20T00:53:26+00:00" > 05/20/16, 00:53 </span>

    Hey, I’ve tested this in TYPO3 7.6.7 and 8.1.0. It’s still an issue.

  3. ondro no-lastname-given commented and changed description <span data-processor="relativetime" data-value="2016-11-28T11:19:54+00:00" > 11/28/16, 11:19 </span>

    Can confirm
    same behaviour on Typo3 v 7.6.11

  4. Felix Nagel commented and changed description <span data-processor="relativetime" data-value="2016-11-28T11:34:24+00:00" > 11/28/16, 11:34 </span>

    @ondro no-lastname-given

    Please do NOT remove useful information from the description.

  5. Stefan Froemken commented <span data-processor="relativetime" data-value="2022-03-11T07:28:53+00:00" > 03/11/22, 07:28 </span>

    As persistence.enableAutomaticCacheClearing is activated by default you only need to add TCEMAIN.clearCacheCmd = [pagesWithYourPlugin] into PageTSConfig of your storages pages.
    Extbase itself contains mechanisms in CacheService to interprete this PageTSConfig and clears cache for you.

    The old solution with $GLOBALS[‘TSFE’]->no_cache = 1 will only render the page uncached, but IMO the old page cache is still valid. So if you or another visits the list page again, your new created record is still missing.

  6. Stefan Froemken commented <span data-processor="relativetime" data-value="2026-11-02T14:54:32+00:00" > 11/02/26, 14:54 </span>

    A follow-up to my comment from 2022. Clearing the page cache after saving still works, either through Extbase’s automatic cache clearing or TCEMAIN.clearCacheCmd. The new record shows up. The flash message problem remains, though.

    After the redirect the first request renders the list page uncached. This rendering picks up the flash message from the visitor’s session. The resulting HTML is written to cache_pages including the message and is delivered to all following visitors with the same usergroups. We reproduced this on 13.4: another user of the same group saw the message of the author.

    Since TYPO3 13 this can be solved in the target action. The frontend request carries a mutable CacheInstruction in the attribute frontend.cache.instruction. TypoScriptFrontendController::generatePage_postProcessing() checks isCachingAllowed() after the content has been rendered and right before the page is written to the cache. So disabling the cache from within a cached Extbase action keeps exactly this one response out of the page cache:

    if ($this->getFlashMessageQueue()->getAllMessages() !== []) {
        $this->request->getAttribute('frontend.cache.instruction')?->disableCache(
            'EXT:my_ext: Flash messages must not be cached',
        );
    }

    Tested on 13.4.35 with curl and a look into the database. An anonymous visitor sees the message once. That response is not stored and cache_pages contains no entry with the message. The following requests are cached as usual. With logged-in users the author sees the message once and another user of the same group never sees it.

    Some notes:

    • Run the check before the template is rendered. <f:flashMessages /> flushes the queue, so the check is always false afterwards.
    • The redirecting action must add the message to the queue of the target plugin (extbase.flashmessages.<pluginNamespace>). That is the queue the ViewHelper reads.
    • The target page must really be rendered uncached after saving. You still need TCEMAIN.clearCacheCmd or the cache tags <table> / <table>_<uid> which DataHandler and Extbase flush. Otherwise the old page comes from cache and your action is not executed at all.
    • This only matters for cached plugins (USER). USER_INT output is not cached anyway.
    • disableCache() requires a non-empty reason and throws an exception otherwise.
    • TYPO3 13+ only. The frontend.cache.instruction attribute does not exist in older versions.