firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

FR: provide maxAge option in PersistenceSettings of enableIndexedDbPersistence() to invalidate cache after specified time

Open oztek22 opened this issue 2 years ago • 4 comments

Describe your environment

  • Operating System version: Ventura 13.0
  • Browser version: Chrome 108.0.5359.124
  • Firebase SDK version: 9.14.0
  • Firebase Product: firestore

Describe the problem

Problem:

  • In current project, user data does not change often . If cached data exists, I retrieve it using getDocFromCache(). Else, I retrieve from server using getDoc().

In some cases:

  • user can change the data from different device or browser. In such cases, data would not be reflected if force cached is enabled.

Probable Solution:

  • introduce maxAge property to enableIndexedDbPersistence to auto delete cached data if it was not updated within defined time (to get the fresh entry from the server)

Relevant Code:

  enableIndexedDbPersistence(db, {maxAge: 86400}) // database will remain in local storage for 86400s (1 day) without any update.
    .catch((err) => {
      console.warn('Failed to persist data: ', err.code, err.message);
    });

oztek22 avatar Jan 03 '23 09:01 oztek22

Hi,

Thanks for filling up this request! The team is going to discuss the feature and will keep you posted.

cherylEnkidu avatar Jan 04 '23 19:01 cherylEnkidu

Internal tracking id: b/269460985

cherylEnkidu avatar Feb 15 '23 16:02 cherylEnkidu

Hi,

This feature is been tracked internally, I will close this github ticket and reporter will be notified in the future when the feature gets implemented.

cherylEnkidu avatar Dec 23 '23 00:12 cherylEnkidu

Hi,

The team decided to keep the ticket open until the feature is implemented or bug is fixed for external visibility.

cherylEnkidu avatar Jan 16 '24 22:01 cherylEnkidu