Skip to content

How can an offline service worker avoid retaining another user's generated media after logout?

Exclude private media and task responses from generic service-worker caching unless you deliberately build a reviewed offline feature. The Cache API does not automatically enforce HTTP cache directives. If your application stores private content offline, bind it to the user lifecycle and clear it on logout or account switch.

PROTECT API ACCESS AND RESULTSAISwapLab team · Editorial methodPublished 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Audit the fetch handler; Define the offline boundary; Test account transitions.
Workflow diagram: Audit the fetch handler → Define the offline boundary → Test account transitions. Read the article for evidence and limits.

Offline storage is application storage

A network response marked no-store can still be placed into a service worker's Cache API by application code. A shared device can then retain private output after the web session changes. Treat that persistence as a product decision, not a performance default.

What to do next

  1. 01

    Audit the fetch handler

    Check broad cache-first or stale-while-revalidate rules for authenticated task, result and thumbnail routes. Add explicit exclusions before generic asset matching so a new private route does not accidentally inherit an offline strategy.

  2. 02

    Define the offline boundary

    If private offline viewing is required, document which content is stored, under which user identity and for how long. Keep application caches distinct from durable provider storage and avoid claiming logout deletes upstream media.

  3. 03

    Test account transitions

    Cache synthetic content as user A, log out and enter as B on the same browser profile. Verify old bytes cannot appear through offline fallbacks, history screens or stale thumbnail requests, including after a service-worker update.

A concrete example

Illustrative example: the app caches its public shell but bypasses Cache API storage for /private-results. After logout, offline mode can show the shell and a sign-in message, without showing the previous user's image preview.

Before you call it ready

  • Private routes bypass generic offline rules.
  • Logout and account switch are tested.
  • Cache API persistence is explicitly reviewed.

When to stop or choose another method

Stop assuming private, no-store alone prevents a service worker from storing a response that your own code explicitly caches.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation