0

I'm writing a web app which fetches a list of files from the server and displays it. The user can click on a folder to descend into it (without actually leaving the page). Retrieving the list can take a while (~10ms per file, which is a lot when you have 2000 files), so I want to cache the results when possible to avoid having to re-fetch it if the user goes into a subdirectory and then back out.

However if I just store the results in some global variable, they'll quickly fill up all the user's memory. Is there some way to tell the browser "feel free to delete this object if you're low on memory", or to be notified when memory is low?

3
  • 2
    they'll quickly fill up all the user's memory That's a whole lot of data, probably much more than you should be sending to the client, I would think? If you have to, you might consider saving to the user's hard drive via IndexedDB, maybe Commented Sep 2, 2018 at 20:07
  • you should cache on the server. Commented Sep 2, 2018 at 20:08
  • A lot of what I want to cache is the actual HTML elements, since recreating them can be slow. Commented Sep 5, 2018 at 17:43

1 Answer 1

2

If you'd like to store those objects on the users computer, to prevent requesting from the server again you'd probably want to use something like LocalStorage to do so.

Store.js provides a nice API around local storage-solutions.

The hard part for you now will be to check which files belong to a certain folder so you can store it. Something like a tree data-structure might be nice to give shape to these folders, paired with an ID you might be able to map them to a place in localstorage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.