DEV Community

Sumit Wadhwa
Sumit Wadhwa

Posted on

How to temporarily store API response?

I'm currently working on a Laravel based application that lets users access their Google drive and have all of their files listed on our front-end.

My question is, how do I temporarily store this API data so that even if user refreshes the page, s/he doesn't have to repeat the google consent screen step all over again, and the data can be shown to the user?

I read couple posts regarding this, though I got confused among different technologies that can be leveraged to achieve this. Techs like Redis, Varnish, HTML5 storage, and most importantly Nginx caching gateway.

Can you shed some light? Thanks

Oldest comments (6)

Collapse
 
devtalhaakbar profile image
Muhammad Talha Akbar

Let's say you stored the API data in local storage. But, if the file info changed then, your local storage will have outdated version of the list. How are you going to deal with inconsistency of information?

Side-question: Why are you not using refresh tokens? I just read that you can use them to get a new access token if the current one has been expired.

Side-note: Local storage has size limitations, I believe.

Collapse
 
swadhwa16 profile image
Sumit Wadhwa

Thanks Akbar.

Collapse
 
nektro profile image
Meghan (she/her)

In this case I would use sessionStorage since if empties after the tab closes but is persistent between refreshes and history changes. With this, the only consistency would come from a user creating a file/folder in their Drive while they had your site open. And since there's no way for you to get a postMessage from drive.google.com then that's about as close as you can get.

Collapse
 
swadhwa16 profile image
Sumit Wadhwa • Edited

Thanks Sean. BTW, how big of a data can be stored in sesssionStorage? So, let's say, if I had an object of at least 60 list items with each item holding a minimum of 4-5kb of data, would it still be appropriate to leverage sessionStorage.

Collapse
 
nektro profile image
Meghan (she/her)

The maximum capacity for sessionStorage ranges from about 5-10 MB depending on the browser.

Collapse
 
netbzz profile image
NetBzz

Use OAuth 2.0 and store the refresh_token. That way you can re-establish the authentication after the original oauth token has expired after 1 hour.

developers.google.com/identity/pro...