Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AC3: cache.evict option to clear orphaned fragment references from root queries #212

Open
jamshally opened this issue Feb 28, 2020 · 3 comments
Labels
📕 cache Feature requests related to the cache project-apollo-client (legacy) LEGACY TAG DO NOT USE

Comments

@jamshally
Copy link

jamshally commented Feb 28, 2020

Feature Request

Provide a cache.evict option to remove the related references from root queries for evicted objects

Justification

When evicting an object from cache, it is usually because it has just been deleted. At present, cache.evict will not remove the related __ref:id items from queries. This means that the developer has to write query read + update functions for every query that references this evicted object. It seems like a nice optimization to automate the removal of these orphaned references

The evict method already has all the data needed to loop the root queries and remove these references (the object cache:id).

As an aside, when evicting an item from cache, it does not seem to immediately disappear from the Apollo Dev Tools cache list, which can be confusing

Cache Demo

See cache evict demo with notes here in a react-apollo-error-template here

@jamshally jamshally changed the title AC3 cache.evict option to clear orphaned fragment references from root queries AC3: cache.evict option to clear orphaned fragment references from root queries Feb 28, 2020
@3nvi
Copy link

3nvi commented Mar 21, 2020

Exactly this! I was about to open a feature request for this, since I feel that in essence it's a tree traversal on cache.data.data. I'm thinking of writing a lib to handle this, but it would be interesting if @benjamn could let us know whether there there are problems with this approach (or even if this is planned)

@Klemensas
Copy link

I came for this exact issue.

Right now the options seem to be the already mentioned read + write, custom typePolicies read to filter out or a UI level filter.

All of them require maintaining a list of queries that need updating and are rather error-prone.
This seems like a common enough use case to warrant some abstractions. Potentially it could be an optional flag in gc.
There seem to be some more related discussions about this here #5

@lorensr
Copy link

lorensr commented Oct 16, 2020

I'd like .evict() to remove all orphaned references, regardless of location in the cache.

@jerelmiller jerelmiller added 📕 cache Feature requests related to the cache project-apollo-client (legacy) LEGACY TAG DO NOT USE labels Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📕 cache Feature requests related to the cache project-apollo-client (legacy) LEGACY TAG DO NOT USE
Projects
None yet
Development

No branches or pull requests

5 participants