Skip to content

API for clearing cache #28

Closed
Closed
@cherniavskii

Description

@cherniavskii

The problem

There's a scenario, which is pretty common:

  • user logs in
  • some user data is fetched
  • user logs out
  • different user logs in and for a moment sees previous user's data

Normally, all user data should be deleted after log out, but there's no API for that at the moment.

I've tried setQueryData function to clear some queries, but it didn't work for me, since it doesn't make those query stale.

I've managed to clear cache like this:

import { queries } from 'react-query';

function handleLogout() {
    queries.length = 0;
}

But I'm not sure if it is safe to do this, since this is not a public API.

Proposed solution

Introduce clearQueries function, which will:

  • clear all queries if called without arguments
  • clear all queries except those provided as first argument.

The second option may be useful for applications, which are partly public. This will allow to clear user data cache, but keep public data cache.

Let me know do you think about that

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions