Repository navigation
v0.5.0 — Opt-in localStorage client cache for deferred components
Highlights
A new opt-in client-side cache for deferred components, decided on the component (not inferred from HTTP headers), with a JS forced-reset API.
Two-tier defer cache (usephp.js)
- L1 — in-memory
Map<URL, DocumentFragment>, per page lifetime. Unchanged behaviour. - L2 —
localStorage, surviving reloads and shared across tabs. Strictly opt-in: persisted only when a component setsDefer::$localCache = true(rendered as a baredata-usephp-defer-cacheattribute). No HTTPCache-Controlis inspected; no time expiry. Components that don't opt in behave exactly like the previous in-memory-only cache, so session-coupled defaults can't leak content on a shared terminal.
Read order is L1 → L2 → network; an L2 hit is promoted into L1. Both tiers are URL-keyed and capped at 64 entries. If localStorage is unavailable, L2 silently no-ops.
Opting in
#[Defer(name: 'announcement-bar', localCache: true)]
// or
fc($render, defer: new Defer(name: 'announcement-bar', localCache: true));localCache and cacheControl are independent (cacheControl governs server/CDN caching only).
Forced reset (JS)
window.usePHP.clearDeferCache(); // both tiers, everything
window.usePHP.clearDeferCache('post-comments'); // every variant of one defer name
window.usePHP.clearDeferCache('/_defer/post-comments?post_id=1'); // one exact placeholder URL
window.usePHP.DEFER_CACHE_VERSION; // current build's valueSince there's no expiry, invalidate via DEFER_CACHE_VERSION (bump on deploy) or clearDeferCache() (runtime). Each persisted record is stamped with DEFER_CACHE_VERSION and version mismatches are rejected/pruned on read and during cap eviction, so a write from an older still-open tab after a deploy can't be served by a newer build.
Docs & tests
- New "Client-side cache & forced reset" / "クライアントキャッシュと強制リセット" section in
README.md/README.ja.md. - Added tests: renderer attribute on/off,
Defer::$localCachedefault/propagation,fc()propagation. Full suite,php-cs-fixer, and PHPStan pass.
Full PR: #20 (review feedback addressed: per-record version race fixed; obsolete Cache-Control parsing removed).
Full Changelog: v0.4.0...v0.5.0