skip to content

In a city-guide app's caches on a shared family tablet, one person's recently viewed venues appear after another signs in: how should the caches be partitioned and wiped?

level: seniorimportance: should knowfreq 45%

answer

  1. who asked, not just what
  2. every tier, not only memory
  3. a URL is not an identity
  4. the response that lands late
  5. unreachable first, then deleted

basics

~10 s

Partition every cache tier by account, including the response cache and search history; drop responses that land after a switch; on logout make that account's partition unreachable at once, then delete it.

solid answer

~40 s

The leak means the cache is keyed by what was requested, not by who requested it. I'd partition **every tier by account**: the memory tier keyed by account or one instance per session, a disk directory per account, the networking layer's response cache per account, and recently viewed, search history and suggestions inside that partition. Only responses that are identical for everyone, such as opening hours, may go in a shared partition, decided per endpoint. Each request is tagged with a session generation, so a response that lands after the switch is discarded or stored only for its own account. On logout I clear the memory tier at once, rename the account's directory out of reach and delete it in the background. Credentials are a separate wipe.

go deeper

for a junior

Recall that cached data belongs to the person who fetched it, and that logging out must remove that person's cached data, not only their sign-in.

for a middle

Explain partitioning each tier by account, and why a response cache keyed only by URL serves one person's personalised page to another.

for a senior

Show the production details: a session generation that discards late responses, a wipe that makes data unreachable before deleting it, a per-endpoint shared partition, and a test with the network off.

for a principal

Set the policy for shared devices across the app: what is kept per signed-in account, what is wiped on logout, how long an inactive account's data may stay, and how that is audited.

Most client caches quietly assume one person. HTTP even names it: a **private cache** is one dedicated to a single user, usually part of the user agent, as opposed to a shared cache that serves many users. A family tablet with a city-guide app breaks that assumption: two or three people sign in and out on the same install, and every tier of the cache sits between them. When the second person sees the first person's recently viewed venues, search history or personalised venue pages, the cause is a cache keyed by what was requested and not by who requested it. ## Partition every tier by account | Tier | Partition by | On account switch | On logout | |---|---|---|---| | Memory tier | account id in the key, or one instance per signed-in session | cleared before the next screen renders | cleared | | Disk tier | one directory per account | point at the new account's directory | directory deleted | | Networking layer's response cache | one per account, or the account in the key | switch with the account | deleted | | Recently viewed, search history, suggestions | the account's partition | switch | deleted | | Shared public partition | nothing personal by construction | kept | kept | A response cache keyed by URL alone is the classic leak: `GET /venues/42` returns a page that includes "saved by you" and friends' reviews, so the same URL carries a different body per account. `Cache-Control: private` does not help; it tells shared caches not to store the response and allows a private cache to keep it, and on a shared tablet the app's cache is the private one serving several people. A **shared partition** for public data, such as opening hours, is an optimisation decided per endpoint, only where the response really is identical for everyone. The safe default for anything unclassified is the account's own partition, and splitting personal fields into their own request is what makes the public part shareable. ## The late response Clearing the tiers is not enough if work started under the previous account keeps writing into them: 1. Give each signed-in session a **generation** number, bumped on every switch and logout. 2. Tag every request, background refresh and prefetch with the generation that started it. 3. On completion, if the tag no longer matches the current generation, discard the result, or store it only in the partition of the account it belongs to. 4. Cancel what can be cancelled at the switch, without waiting for it: offline, a request may hang until its timeout and would freeze the switch. ## Wiping without stalling A large disk partition can take a while to delete. So make it **unreachable first, then delete it**: point the cache at the new account's partition and rename the old directory to a to-be-deleted name in one quick step, clear the memory tier at once, and delete the renamed directory in the background, finishing on the next launch if the app is ended mid-way. Old data is never readable in between. ## Keep or wipe on a switch - **Explicit logout:** wipe that account's cached data. The person has said they are leaving this device. - **Switching while both stay signed in:** keeping each partition makes switching back fast and is reasonable if the partitions are isolated; the cost is that the data stays on the device, which some products or users will not accept. - **One app-wide ceiling:** all partitions share the disk budget, so evict across them, with inactive accounts' entries first. ## Mistakes interviewers listen for - Clearing only the memory tier and assuming disk files are private to the person who caused them. - Trusting a URL-keyed response cache because each request carries a different token. - Storing a response that lands after the switch under the new account because it is newer. - Believing logout only means deleting tokens; the cached venues and search history are the visible leak. - Putting public and personal responses in one partition by default. ## Where this question stops - Deleting credentials and keys at logout belongs to the device-security part of the design; this question wipes cached data. - Tearing down session-scoped objects in dependency injection is asked with the app's module structure. - Which user data lives in the persistent store, and how it is split per account, is the store-choice question. To test it: sign in as one person, browse and search, sign out, turn the network off and sign in as another person; nothing from the first account may appear on any screen. Repeat on a slow network so the first account's requests land after the switch.

  • Can public venue data be shared across accounts on the tablet?
    Only per endpoint, and only when the response is identical for every user: opening hours yes, a venue page that embeds a saved flag or friends' reviews no. Splitting personal fields into their own request lets the public part be shared, and anything not yet classified defaults to the account's own partition.
  • How do you wipe a 100 MB partition without stalling sign-out?
    Make it unreachable before deleting it. Point the cache at the new account's partition, rename the old directory to a to-be-deleted name in one quick step, and clear the memory tier at once. Delete the renamed directory in the background, finishing on the next launch if the app is ended mid-way.
  • How would you test that one account never sees another's venues?
    Sign in as one person, browse venues and search, sign out, turn off the network and sign in as another: no screen, suggestion or recent list may show anything from the first account. Repeat with a slow network so the first account's requests complete after the switch.

  • Clearing the memory cache at logout is enough, because disk files are private.
  • A response cache keyed by URL is safe because each user sends a different token.
  • A response that arrives after an account switch can be cached for the new account.
  • Logging out only needs to delete the tokens; cached venues are harmless.
  • Public and personal responses can share one cache partition by default.