hack4impact-uiuc / 7000-languages

Helping Indigenous communities around the world teach, learn and sustain their languages
GNU General Public License v3.0
12 stars 2 forks source link

File Cache for Images/Audio #241

Closed ashayp22 closed 1 year ago

ashayp22 commented 2 years ago

Motivation

Currently, @masgras2 switched to loading in Images on the client-side in an asynchronous manner instead of a synchronous manner, meaning the Images aren't loaded one after another. Instead, Images are loaded in at the same time and appear once they load in. However, this has some flaws:

  1. Images show one by one, instead of all showing at the same time. This is because this is dependent on how quickly the API handles each GET \image request. In order to resolve this, we can increase the load that the API can handle on AWS.
  2. There's no way of checking if the image that we want to get already exists in Expo Filesystem. This is a drastic performance hit on the client-side because making GET \image requests is O(n) and expensive.

Linked issue: #176

High Level

We need to build a cache that maps Vocab Items to an Expo Filesystem URI. This cache will be stored in AsyncStorage. This will be used to check if a file we want already exists on a client's device, as well as removing files that haven't been used in a long time. The cache will also implement LRU policy along with invalidating files after a specific period of time.

Methods

It would be nice to have the PUT method directly integrated with our axios code that fetches and uploads Audio/Images from the backend (in client/src/api/api.js, see downloadImageFile, downloadAudioFile, uploadImageFile, and uploadAudioFile. This is because whenever we fetch a file from the API, we can to keep record of that in the cache. Also, whenever we upload a file to the API, then we want to keep that file saved locally in Expo filesystem.

This is a tricky issue, especially if you haven't worked with caches and the Expo Filesystem before, and this should take at least 3 weeks to fully complete. We can break this up into multiple parts:

  1. Be able to save files in the cache after downloadImageFile() or downloadAudioFile()
  2. Get files from the cache when already saved
  3. Be able to save files in the cache after uploadImageFile() or uploadAudioFile()
  4. Delete files from the cache when we run out of space

Resources