Clearing cache for log out in Relay.js app

1.4k Views Asked by At

I have a Relay app and I want to clear cache for a component that displays after logging in. I tried passing a currentRelay.store into my Relay.Router and implementing a currentRelay.reset() which sets that store to a new Relay.Environment, then calling that after logout. The cache is still stored for some reason. I also tried calling this.props.relay.forceFetch({}) and this.forceUpdate() in componentDidMount(). The only way I can get the cache to clear is by manually refreshing the page. I wonder if there's a bug in Relay.Environment or I'm doing it wrong.

1

There are 1 best solutions below

0
On

in a environment file just get response cache from QueryResponseCache which you can get from relay-runtime im using 8.0.0 so you can check your verison of relay runtime and get queryresponsecache from relay-runtime

const cache = new QueryResponseCache({ size: 250, ttl: oneMinute });

after jutst get token from localstorage if token is null then do cache.clear() e.g,

 if (!token) {
cache.clear();
}