Skip to content
loading...

How to temporarily store API response?

chandlerbing016 profile image Sumit Wadhwa github logo ・1 min read  

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

twitter logo DISCUSS (6)
Discussion
markdown guide
 

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...

 

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.

 
 

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.

 

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.

 

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

Classic DEV Post from Jul 30 '19

PublishTo.Dev: Scheduling article publishing on dev.to

Sumit Wadhwa profile image
Web Developer