Repository navigation
[BUGFIX] Treat a cache entry without generated file as missing - #479
lochmueller merged 2 commits into
Conversation
GenerateMiddleware reported a page as "already in cache" as soon as the database entry was valid, without looking at the file system. If the generated files are gone while the entry is still there, the page is not written again until the entry expires, and every request is handled by PHP in the meantime. That happens whenever the cache directory is emptied without the database table, e.g. a deployment step like "find <cache dir> -delete" right after a cache flush: a page requested between the flush and the delete keeps a valid entry but loses its file. The entry now only counts as valid if at least one generated file exists (plain, .gz, .br or .php, depending on the enabled generators). Otherwise the page is stored again, which rewrites entry and file. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
thanks. do you check the StaticFileCache Backend? The "has" method in there, check the existence of the file and also the existence of the DB entry. https://github.com/lochmueller/staticfilecache/blob/main/Classes/Cache/StaticFileBackend.php#L140 So a more robust way would be, just call the "has" in front of the "get" for the cache, to also check the file. This will reuce the addional dependency of the IdentifierBuilder in the middleware. What do you think? Regards, |
lochmueller
left a comment
There was a problem hiding this comment.
Please change the resolving of the files to the "has" method (comment above)
Review feedback: the middleware should not depend on the IdentifierBuilder. StaticFileBackend::has() cannot be used for this, it is true when either the file or the database entry exists. A new hasStaticFile() checks the files only (plain, .gz, .br, .php) and reuses getFilepath(), so hashed identifiers are handled as well. The middleware asks the backend of its cache; other backends keep the old behaviour (the entry decides). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the review. I checked Your point about the extra dependency in the middleware is fair though, so I pushed a change: the file check now lives in |
|
Thanks... Merged. |
Short description
GenerateMiddlewareanswers "already in cache" as soon as the database entry is valid, without checking that the generated file exists. If the file is gone and the entry is still there, nobody writes the page again until the entry expires, and every request is handled by PHP in the meantime.How it happens
Anything that empties the cache directory without the database table, for example a deployment step such as
find <cache dir> -mindepth 1 -deleteafter a cache flush. A page that is requested between the flush and the delete gets a new entry plus file, then loses the file and keeps the entry. The entry is valid for the full lifetime, sohasValidCacheEntry()keeps returningtrueandset()is never called again.From the outside it looks like SFC is installed and active, but the page is rendered by PHP on each request.
What changed
hasValidCacheEntry()additionally requires that a generated file exists for the URI. Otherwise the page is stored again, which rewrites the entry and the files, so the situation heals itself on the next request.The check lives in a new
StaticFileBackend::hasStaticFile()(plain,.gz,.bror.php, depending on the enabled generators). It reusesgetFilepath(), so hashed identifiers are handled.has()cannot be used for this: it isis_file() || parent::has()and therefore also true for an entry without file. The middleware asks the backend of its cache; any other backend keeps the old behaviour (the entry decides). The extrais_file()only runs on requests that reach PHP anyway.Tests
has()true,hasStaticFile()false; every generated file variant -> true; unknown / invalid identifier -> falsephpunit(401 tests),php-cs-fixerandphpstanare clean.Related Issue
None found.
More Details
main. The same method exists in the TYPO3 13 line, I can open a second PR forv13if you want it there.🤖 Generated with Claude Code