Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache final Responses #73

Closed
lidel opened this issue Feb 29, 2024 · 4 comments · Fixed by #92
Closed

Cache final Responses #73

lidel opened this issue Feb 29, 2024 · 4 comments · Fixed by #92
Assignees

Comments

@lidel
Copy link
Member

lidel commented Feb 29, 2024

afaik Response produced by service worker is NOT cached by the browser, unless it is explicitly put in the cache. Right now we don't do that, so page reload trigggers fetch of all chunks as blocks, which are returned from cache and re-assembled again, rather than the final result being returned from cache.

If we add final Responses to cache, page reload will not trigger block requests for resources which were already handled.

Ref.

@SgtPooki
Copy link
Member

SgtPooki commented Mar 4, 2024

we should be caching only 2xx,3xx permanently (for IPFS only). maybe 15s for errors.

IPNS is being cached at verified-fetch layer (IIRC)

@2color 2color self-assigned this Mar 6, 2024
@2color
Copy link
Member

2color commented Mar 6, 2024

I've been investigating this and what the advantages of using the cache API would be over IndexedDB (which is already implemented but not used)

The following is a useful resource https://medium.com/dev-channel/offline-storage-for-progressive-web-apps-70d52695513c#.19w8r1c4o

Some initial insights:

  • It seems that both IndexedDB and the Cache API share the same storage quota
  • By using the indexedDB block store, we may benefit from more granular block level caching
  • "Items in a Cache do not get updated unless explicitly requested; they don't expire unless deleted." The same applies to indexedDB

@lidel Are there any specific benefits of the Cache API over indexedDB you are aware of?

@lidel
Copy link
Member Author

lidel commented Mar 7, 2024

@2color Thanks for looking into this. Indeed, shared quota is a bummer, but let's remember it applies only to Cache API, not individual block responses.

Cache API is still something we need. Cache API stores final bytes produced by IPFS stack, which means work necessary for turning IPFS DAG into final file occurs only once, and not on every page load for every image etc on the page.

Block level caching is useful when loading new subpath on a path we already visited, but iiuc we already get that from trustless-gateway.link responses being cached (responses have cache-control header that tells browser to cache each block for as long as possible), so lower priority.

I think the priority is to set up Cache API, especially for /ipns/.. content path responses, and then fine to look into IndexedDB-based blockstore and see if it improves any metric.

@2color
Copy link
Member

2color commented Mar 12, 2024

Somewhat related, I discovered we don't set the right cache-control headers in @helia/verified-fetch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants