Closed abhionlyone closed 5 years ago
Cache should not have any issue. Can you post your code here?
var storage = new Storage({
size: 1000,
storageBackend: AsyncStorage,
defaultExpires: null,
enableCache: true,
sync: {}
})
and I'm saving the user data with the below code:
storage.save({
key: 'user',
data: res.data,
expires: null
});
and on user logout:
storage.remove({
key: 'user'
});
The thing is if you reload the app, it will load the new user data. So I assume on reloading the cache is getting expired.
Cache is just in memory and should not affect any logic. What is special in your scenario?
@sunnylqm Ok Thanks!! When I get some time, I will create a simple application and try to replicate the scenario.
Meanwhile, I've set enableCache: false
and everything seems to be working clean & nice.
@sunnylqm 我也遇到了同样的问题 在开发环境下 我的react-native的版本是0.55.4 react-native-storage的版本是0.2.3 我使用的场景是这样的,在app登录成功之后跳转页面并调用相关借口获取数据并存到缓存中: ` export const storage = new Storage({ size: 1000, storageBackend: AsyncStorage, defaultExpires: 1000 3600 24, enableCache: false }) // 全局变量 global.storage = storage;
storage.sync = ASYNC;
在退出app时调用如下的方法清空所有key-id的缓存:
clearLogout = () => {
LOGOUT().then(res => {
storage.clearMap();
this.props.rootStore.init();
this.props.navigation.reset([NavigationActions.navigate({ routeName: 'LoginWrapper' })], 0)
},err => {
})
}
` 但是当我退出登录跳转到登录界面,在不重启app的情况下直接再登录,这时候app的缓存是上一个的缓存,但是当我重启app之后就正常了 然后我设置enableCache: false的时候就不会出现这个情况 求解中。。。
@1111mp Try new 0.2.4 or 1.0.0-beta.1 version.
@AbhiOnlyOne remove is an async promise so you need to await it or use then to ensure the operation orders
@sunnylqm Thanks!
@sunnylqm Thank you. I'll try it.
@sunnylqm I just tried it,but the problems still exist in 1.0.0-beta.1 versions. I must to set enableCache: false
and the problem can only be solved.
That's how I read the data:
How does this loadAddrBook
related to removing data?
Yes, they don't matter. I logged out after clearing the cache, and then logged in.If I don't set it up like this,the read cache is still the last cache.When I restarted App, the cache returned to normal. I don't know why.
And why do you save data like {key: 'addrBook', id: 'addrBook'}
? This should be a key only data and should be removed manually.
I've set
enableCache: true
and this is causing few issues in the app.When the user is logged out, I'm removing all the user data with the below code:
But the problem is If I immediately sign in with a new user account, The old user account data is loaded due to
enableCache: true
.When I set
enableCache: false
everything works fine.So, I'm wondering if there is an option to manually expire cache when a user does log out.