Should advanced cache allow promises? #1331
Unanswered
mnightingale
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently experimenting with the new custom cache in
1.0.0-beta.9
.I'll be using it within a react native project and the intention is to download files to disk (I'm currently using Expo FileSystem)
For example the below snippet shows the fetcher takes the props
source.uri
(like a ImageURISource) which will be a remote https address and the data.source.uri from swr will resolve to a local path to the file.The next step is I want to create my own cache provider that resolves the local path if it exists before the request has happened, from what I understood I'd want a custom cache provider for this?
So I think as a first draft I want to do something like:
But this wont work because the cache doesn't support returning or handling promises.
swr/src/types.ts
Lines 174 to 178 in cb79966
Eventually I'll want to make options to make the fetcher not fetch if local exists, or send if-none-match headers with the cached ETag (ETag from in-memory cache or local file, I may end up needing persistence of recently used files ion order to clear some of the files).
Is it possible for the cache to handle promises or is their a fundamental reason it doesn't?
Perhaps I'm going about the above solution the wrong way?
Is there any documentation of correct handling of cache keys since I couldn't find any, but I noticed
url
,$err$url
and$req$url
calls.Thanks for reading, superb module.
Beta Was this translation helpful? Give feedback.
All reactions