Page caching: clearing cache on data changes
0 reputation · 25 Aug 2023, 16:33 UTC
0 reputation · 25 Aug 2023, 16:33 UTC
When restoring application data from a backup, a developer wants to ensure that previously cached pages reflect the updated state rather than lingering stale DOM content.
Framework7’s Router keeps a page cache to speed transitions, but the documentation does not explicitly state whether this cache is automatically invalidated when the underlying data model is updated or when a backup is restored. If the cache persists unchanged, users may see outdated information until a manual refresh or navigation.
onPageReinit or custom events) can be used to invalidate or rebuild a cached page?No. Framework7’s Router page cache is a navigation and DOM cache, not a reactive data cache. It does not watch your application data model or detect that a backup has been restored. A page initialized before the restore keeps its existing DOM node; returning to it later shows the old markup unless your code explicitly updates it or forces the router to rebuild the page.
Confirmed: the router keeps previously rendered pages in the view to speed transitions. Likely: because a page’s content is rendered when that page is initialized, a cached page initialized before the restore will not re-render automatically. Only code that mutates the DOM node, or router options that discard the cached node, will make restored data visible.
The correct fix depends on page type. Please confirm whether the affected pages are plain HTML/JS routes or Framework7 component pages (React, Vue, or Svelte). That single detail determines whether you patch the DOM in a lifecycle hook or rely on component reactivity.
pageBeforeIn / page:beforein or pageReinit / page:reinit in the route definition to re-query the restored data and update the DOM.pageInit / page:init; it runs on first initialization and may not run again for a cached page.reloadCurrent, reloadAll, or ignoreCache, or call router.refreshPage() / router.clearPreviousPages() where available. Scope the reload to the affected route to avoid discarding unrelated cached pages and losing scroll or form state.pageReinit, which can conflict with the component renderer.Event names and router options have changed across Framework7 majors—for example, camelCase pageReinit versus kebab-case page:reinit, and the exact semantics of ignoreCache and reloadAll. Verify against your installed version rather than assuming one API shape.
pageInit, pageReinit, and page:beforein to see whether A’s DOM text changes without a manual reload.reloadCurrent / reloadAll / ignoreCache or router.refreshPage() / clearPreviousPages() as supported, then verify A shows restored data on router.back, browser back, and swipe-back if enabled.pageBeforeRemove / page:beforeremove around forced reloads to confirm cache entries are actually cleared, not merely hidden.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.