sunnylqm / react-native-storage

local storage wrapper for both react-native and browser. Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.
MIT License
3.01k stars 268 forks source link

How to Ignore expiry #268

Closed Kyu closed 1 year ago

Kyu commented 1 year ago

Is it possible to get the details of an expired key?

or, if not, is it possible to load the current expired object inside of the sync function?

sunnylqm commented 1 year ago

what's your use case?

Kyu commented 1 year ago

My api has an exposed last_updated key, which returns a datetime

I plan to ping that last_updated endpoint on sync and check if its greater than the local last_updated. If its not, then the sync function will return the current local version of the key, as nothing has changed.

This is to save user bandwith

sunnylqm commented 1 year ago

This sounds weird, and i've never seen such design. Why bother to check the last_updated on client? Why not do it on server? in this way:

  1. you save more code on client
  2. more flexiable to control the update interval on server anytme
  3. save roundtrip in just one call (return new data or no in just one api call. in your proposal you should do 2 right? first check then fetch)
  4. avoid unintended calls from external parties (if any)
Kyu commented 1 year ago

The server has no way of knowing if the client has the most updated info.
edit: I guess client could send server the datetime, but that's not needed

I could check via auth, but users are not required to authenticate to log in

edit: I plan to use websockets in the future, but right now checking and updating seems like a good temporary solution.

even with your solution where the server returns null, I need a way to tell the cache to refresh the current version of data

sunnylqm commented 1 year ago

sounds you still need a custom request interceptor instead of simple storage sync

Kyu commented 1 year ago

i just want a way to refresh the expiry date of an object without making an expensive call. I will try to create my own fork with this functionality.

Edit: for future readers, I just set all my keys to never expire, and gave every object its own expiry field. On loading an object, i check the expiry, and if it expired, i check the server for any updates. If no updates, I refresh the expiry