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

Compatibility with apollo3-cache-persist (Reopening issue 35) #47

Closed
ericaiq opened this issue Jan 31, 2022 · 8 comments
Closed

Compatibility with apollo3-cache-persist (Reopening issue 35) #47

ericaiq opened this issue Jan 31, 2022 · 8 comments

Comments

@ericaiq
Copy link

ericaiq commented Jan 31, 2022

Hi, I'm having trouble using apollo-cache-policies along with the apollo3-cache-persist library in a React Native project. This issue is most likely the same as #35. I have gotten an InvalidationPolicyCache to work without persistence. However the data is never refreshed once I persist the cache.

I modified a sandbox to repro the issue here. (Original sandbox from this issue)

Repro Steps:

  1. Click a film
  2. Wait 10 seconds for cache to expire
  3. Navigate back

Expected:
4. List is refreshed with a new network request

Actual:
4. List is not refreshed, the data is loaded from the cache.

The same steps result in the list being refreshed if apollo-cache-persist is not being used (comment out line 47). Any advice for getting these two libraries to work?

Let me know if you need more info. Also, this is my first time working with Apollo. This could easily be my fault. Thanks!

@mogelbrod
Copy link

mogelbrod commented Jan 31, 2022

I also noticed this recently as I'm starting to experiment with cache invalidation more and more. To be fair I'm not entirely sure that using both libraries has ever worked for me - I might have accidentally temporarily disabled the persist plugin while testing.

Neither v1.5.0, v2.0.0, v2.0.2 nor v2.3.0 seems to ever invalidate entries when combined with [email protected].

@danReynolds
Copy link
Collaborator

Thanks for the repro! I'll take a look later today

@danReynolds
Copy link
Collaborator

Hey @ericaiq ! Getting back to this, had a busy week with work. Thanks for the great sandbox, found the issue. We had not been reinitializing all of the necessary objects when apollo3-cache-persist would call cache.restore() on startup, causing the TTLs to not work. Fixed in: #48 and released under version 2.4.0. Let me know if that works for you!

@ericaiq
Copy link
Author

ericaiq commented Feb 3, 2022

Thanks for looking into this! We actually decided to go in a different direction for the project I am working on.

I'm still noticing some weirdness in the sandbox. Notably that the initial call to allFilms isn't cached. I'm not sure if this is a sandbox set up issue or an issue with the cache.

Repro:

  1. Set apollo-cache-policies to 2.4.0
  2. Click a film
  3. wait 10 second (for cache to expire)
  4. click back
  5. The list of films is now empty (Expected behavior is that the list is refetched)
  6. Click Load More
  7. Click a film
  8. Click back
  9. List is still empty and new films are not fetched
  10. Refresh page, list is still empty. I think there is an empty list in the cache?

@mogelbrod
Copy link

Can confirm that what @ericaiq described above is happening for me too.

@danReynolds
Copy link
Collaborator

@mogelbrod I think I found an issue and just released 2.4.1. When I run the original sandbox posted above on 2.4.1 (make sure to run window.localStorage.clear() to get rid of any lingering data from cache persist under 2.4.0) and perform steps 1-10 it seems to be working. If it's not too much trouble, take a look and see if it's still reproducible when you have time.

@mogelbrod
Copy link

@danReynolds looks like v2.4.1 fixes the issue with relay style pagination, much appreciated!

@danReynolds
Copy link
Collaborator

@danReynolds looks like v2.4.1 fixes the issue with relay style pagination, much appreciated!

Woohoo! That was a tricky one. Thanks for your patience and persistence! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants