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.02k stars 268 forks source link

Warning Expired! Params, when i using 0 in defaultExpires and expires #271

Open mr2726 opened 7 months ago

mr2726 commented 7 months ago

Hello everyone see my code

import React, { useState, useEffect } from 'react';
import { View } from 'react-native';
import Storage from 'react-native-storage';
import AsyncStorage from '@react-native-async-storage/async-storage';

const storage = new Storage({
  size: 1000,
  storageBackend: AsyncStorage, 
  defaultExpires:  0, // <- talking about this line
  enableCache: true,
});
storage.save({
  key: 'first',
  data: {
    from: 'some other site',
    userid: 'some userid',
    token: 'some token'
  },
  expires: 0 // <- talking about this line
});

const _loadData = () => {
  storage.load({
    key: 'first',

    autoSync: true,
    syncInBackground: true,
  })
  .then(ret => {
    console.log(ret);
  })
}

function App(): React.JSX.Element {
  useEfect(() => {
    _loadData()
  }, [])
  return (
    <View></View>
  );
}

export default App;

so when i'm running this code i see the following warn.

 WARN  Expired! Params: {"ret":{"rawData":{"from":"some other site","userid":"some userid","token":"some token"},"expires":1711700444828},"key":"first","autoSync":true,"syncInBackground":true}

when i am chang the 0 to default params like 1000 * 3600 * 24, it works fine.

sunnylqm commented 7 months ago

0 means expire immediately. what do you expect?

Primilink commented 6 months ago

Zero is not the same as null, if you want it to never expire use null instead of 0

albornozgusti commented 5 months ago

hi, be careful with the values that you are using. as they said, Zero is not the same as null. let me show with a screenshot with RunJs: image

line 2 and 3 are basically the same, but i want you to know that "null" is not the same as "empty" if you want to see from other perspective. Anyway, i suggest you to read the docs.