ipfs-shipyard / service-worker-gateway-2019-poc

[ARCHIVED] 2019 PoC of IPFS gateway fully running on a Service Worker. For modern (2024+) version see https://github.com/ipfs-shipyard/service-worker-gateway
MIT License
61 stars 11 forks source link

Add caching files with service worker #4

Open vasco-santos opened 6 years ago

vasco-santos commented 6 years ago

We will have improvements in the time for getting files if we cache them using the service worker. In this context, the service worker would start by verifying if the file is already stored in the cache. If it is stored there, it can be returned immediately. Otherwise, it should use the running IPFS node, in order to get the file.

It is also important pointing out that, as we intend to support all types of files (consequently, different sizes), some of them may not be the best candidates for being cached. This way, it is necessary to decide a good criterion for caching a file.

Reference: https://developers.google.com/web/ilt/pwa/caching-files-with-service-worker

fsdiogo commented 6 years ago

What if a file is cached but isn't available in IPFS anymore?

Just wondering what is the best approach to something like this 🤔

linonetwo commented 6 years ago

Caching small file is easy, just get link.size and if size is smaller than a threshold, we add it to cache.

We can get link.size here.

I have another two thought:

  1. Can we just add ipfs node's repo to cache? (Cache seems to have no limit in desktop browsers though you will be warned if it's getting huge)
  2. Can we send a notification to the user if the object we returned is outdated? By doing so: Besides respondWith cache, we fetching the object from ipfs, and compare it with the cache.
linonetwo commented 6 years ago

Article about caching stream https://zeit.co/blog/streaming-server-rendering-at-spectrum