NerdWalletOSS / apollo-cache-policies

An extension of the Apollo 3 cache with support for advanced cache policies.
Apache License 2.0
152 stars 22 forks source link

Prevent makeCachedVar from overwriting existing value? #52

Closed seanaguinaga closed 3 weeks ago

seanaguinaga commented 2 years ago

Hello

How do you make sure that makeCachedVar doesn't overwrite the existing value if there is one in the cache?

I am not sure how you would initialize something without rewriting what is there? Is there a read-only function not in the docs?

seanaguinaga commented 2 years ago

undefined values also seem to be written - which I saw a commit that should have made that impossible?

danReynolds commented 2 years ago

Hey @seanaguinaga ! So the default value provided to the makeCachedVar API is replacing an existing value in the cache when it shouldn't be? Yea it should only use the default value instead if there isn't a falsy value there already. Do you have a repro I can look at?

seanaguinaga commented 2 years ago

My mistake!

I was not importing the sync version, but I was calling it synchronously.

Switched to sync and that issue is gone!

🤦‍♂️ it was one of those days

I noticed that even persistCacheSync has persistenceMapper on it, but it does not fire, is that intentional?