Skip to content

[BUGFIX] Flush frontend cache when AI label metadata changes - #35

Open
achimfritz wants to merge 1 commit into
mainfrom
bugfix/caching
Open

[BUGFIX] Flush frontend cache when AI label metadata changes#35
achimfritz wants to merge 1 commit into
mainfrom
bugfix/caching

Conversation

@achimfritz

Copy link
Copy Markdown
Contributor

No description provided.

@achimfritz
achimfritz requested a review from o-ba September 1, 2026 13:34
@achimfritz
achimfritz force-pushed the bugfix/caching branch 2 times, most recently from 6ba6a19 to 698b3c3 Compare September 1, 2026 15:28

@o-ba o-ba left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug is real and I even reproduced it. But most of the diff is IMOunnecessary. TYPO3’s DataHandler already flushes the page-cache tag sys_file_metadata_<uid> on every write to that table, with no feature flag involved. What’s missing is only the tag on the page-cache entry. On a fresh v14 install the bug doesn’t occur at all, because core’s frontend.cache.autoTagging is on there.

So I see following options:

  1. Only configuration, zero code: Set frontend.cache.autoTagging = true and document it. Core then tags every page cache entry with sys_file_metadata_<uid> from ResourceStorage::getPublicUrl() and DataHandler flushes it. The flag is on for instances installed on v13.3+, manual for upgraded ones.

  2. Keep one extension-side tag and drop the rest: Classes/Service/CacheHelper.php, keep addCacheTag(), delete invalidate(), getServerRequestInterface() and the CacheManager dependency, rename to something that says what it does (FrontendCacheTagger or similar), and take the request as an argument:

public function addCacheTag(FileReference $fileReference, ?ServerRequestInterface $request): void
{
    // Unconditional, also for unflagged files: a file that gets flagged later must
    // invalidate the pages that already rendered it.
    $metadataUid = $fileReference->hasProperty('metadata_uid')
        ? (int)$fileReference->getProperty('metadata_uid')
        : 0;
    $collector = $request?->getAttribute('frontend.cache.collector');
    if ($metadataUid <= 0 || !$collector instanceof CacheDataCollector) {
        return;
    }
    // Core's own tag name, the one ResourceStorage::getPublicUrl() emits under
    // frontend.cache.autoTagging, and the one DataHandler already flushes on every
    // sys_file_metadata write. So nothing here has to flush anything itself.
    $collector->addCacheTags(new CacheTag('sys_file_metadata_' . $metadataUid));
}

FileMetadataViewHelper:

$this->cacheTagger->addCacheTag(
    $fileReference,
    $this->renderingContext->hasAttribute(ServerRequestInterface::class)
        ? $this->renderingContext->getAttribute(ServerRequestInterface::class)
        : null
);

What Option 2 doesn’t cover, and the README should say: the tag is only added where a template calls <ailabel:fileMetadata>. Only Option 1 covers those, which is why the feature flag is the primary fix and the tag the fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants