Open booboothefool opened 4 years ago
You need to explicitly return
the value you want in sync method
@sunnylqm Thanks!
const storage = new Storage({
// maximum capacity, default 1000
size: 1000,
// Use AsyncStorage for RN apps, or window.localStorage for web apps.
// If storageBackend is not set, data will be lost after reload.
storageBackend: AsyncStorage, // for web: window.localStorage
// expire time, default: 1 day (1000 * 3600 * 24 milliseconds).
// can be null, which means never expire.
defaultExpires: 1000 * 3600 * 24,
// cache data in the memory. default is true.
enableCache: true,
});
storage.sync = {
stamina(params) {
storage.save({
key: 'stamina',
data: 10,
expires: 1000 * 3600 * 24,
});
return 10;
},
};
const stamina = await storage.load({
key: 'stamina',
autoSync: true,
syncInBackground: false,
});
That gives me the expected result of 10 after 24 hours. It seems to be working for most people, however some of my users are still reporting that it never resets, which means they're stuck so they can't do anything. Are there special cases where it can get stuck and doesn't sync again?
Oh, I am on iOS.
Hi so I am trying to have my storage reset every 24 hours. Say a user has 10 stamina. Throughout the day, they may use some and run of stamina when it hits 0. After 24 hours, it should reset back to 10 so the user can use it again.
I noticed with
syncInBackground: false
the data is alwaysundefined
. It doesn't seem to wait and sync back to 10 before loading, but is just stuck asundefined
.syncInBackground: true
does seem to update it back to 10 sometimes though if the app is reopened, but not reliably.I am finding these behaviors confusing because it seems like I want
syncInBackground: false
after reading the description, but that doesn't work at all for me, whereassyncInBackground: true
is closer to the desired behavior.Basically I just want the stamina to reset to 10 every 24 hours.