Skip to content

Write page-cache files atomically to avoid partial cache reads #84

@mehul0810

Description

@mehul0810

Finding

Page-cache metadata and body files are written directly to their final paths with file_put_contents().

Evidence

  • src/Modules/Cache/PageCache.php write_cache_meta() writes JSON metadata directly to the final meta path.
  • src/Modules/Cache/PageCache.php write_cache_body() writes HTML directly to the final body path.
  • Readers call read_cache_meta() and read_cache_body() directly against those same final paths.

Impact

The request lock prevents duplicate writers for the same key, but it does not prevent concurrent readers from seeing partially-written files. A busy site can serve truncated HTML or ignore freshly-written metadata/body pairs during cache regeneration.

Suggested fix

Write metadata and body to temporary files in the same cache directory, then atomically rename them into place. Write the body before the metadata so a fresh metadata file never points at a missing or partial body file.

Acceptance criteria

  • Cache writes use temp-file-plus-rename semantics.
  • Readers never observe partial body or metadata content.
  • Existing cache key/file naming remains backward compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cachePage cache, menu cache, preload, invalidation, observability, or cache settings.area: performancePerformance-sensitive behavior, page weight, caching, preloading, or resource hints.bugConfirmed or likely defect affecting runtime behavior, UX, compatibility, or data handling.priority: highImportant for the next planned release or high user impact.risk: release-blockerShould be resolved or explicitly deferred before the target release ships.status: readyScoped enough for implementation without major open questions.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions