-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fetch cache #3756
Comments
Considering building a solution in TS in the meantime. @TonyLianLong wouldn't this just be Lines 449 to 450 in 63293a9
|
Yes, I agree. It would be ideal it could be done at the rust level.... |
Most of the logic and capability is in |
@brandonkal While implementing the redirection for
You probably need to first create a response which is opaque-redirect filtered, and then return. |
That makes sense @TonyLianLong For my particular use case I ended up deploying a serverless proxy worker that wraps text in a JS module default export, thus using Deno's existing caching mechanism for static imports. So I am no longer working on a TS interim solution. If someone does start working on this, the best route is to use Rust for the default cache (could function without allow-write/read because Rust is priviledged) but allow the user to provide an alternate Cache instance on the TypeScript side. If a TypeScript implementation was provided, the runtime would naturally require the appropriate permissions. Refer to make-fetch-happen and in particular #opts-cache-manager This would mean a sane default cache mechanism implemented in Rust but the flexibility for the user to specify an alternate Cache mechanism (i.e. using Redis) using the standard Cache API. |
As alluded to above, a fetch cache could be used for static non-code resources, such as .proto files. But it won't be ideal if it would still require |
That's one of the issues with npm packages. They can download anything and put it in the PATH. The cache would expire based on the headers the server specifies. If you don't want expiration you specify that where you serve the file. Rather than making a fs call in the module, you make a fetch call, and if reaching out to the network can be avoided because of a valid cache, it is. I suppose it may make sense to add another permission flag i.e. |
CacheStorage and Cache API's are used for this. Cache: https://developer.mozilla.org/en-US/docs/Web/API/Cache Cache Storage: https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage It may also be a good default for third party modules that need to cache data non persistently. |
Implementing There is #9931 about how the internal cache needs to respect headers and behave more browser-like. |
As far as I can tell, |
The Cache API is now implemented. I believe this issue can be closed. |
The Cache API is something completely different in my opinion. So it doesn't seem right to close this issue because the Cache API was implemented. What the issue author asked was for fetch to automatically cache responses based on e.g. the Let's say I keep fetching Using the Cache API I must myself parse the headers to understand how to properly cache the response (if I understand correctly), which would be a lot of work and not really related to this issue in my opinion. |
Actually, yes, you're right. The closure of this issue appears to be a mistake. |
Not sure how I missed that 😅. Definitely would be a nice-to-have feature. Fetch in Deno should work as closely to browsers as possible (outside of maybe allowing the |
It's still closed. Let's begin by opening it? |
@JoakimCh When an issue is closed, you often have to @lino-levan mention them directly. I'd be very interested in respecting the cache headers for this feature, since it could enable fully automatic disk cache for things like signed S3 urls that has the necessary headers. Would be even nicer if keys could get deleted after expiry, but afaik that's not part of the specs |
I'm looking for this feature as well. I can imagine a few reasons why the Deno team might not want to make it the default (ex: why cache something downloaded by a script that runs only once.) I'd be fine with making the caching opt-in. It could even be implemented in |
This is actually a very interesting discussion! But the most important thing for me is NOT persistency, but instead to have a runtime HTTP cache to avoid hammering a server when the data should be cached (as defined by the HTTP protocol). But I think that maybe there should be a permission flag to allow a HTTP cache to persist outside of the script runtime e.g. |
It would be useful to see Deno use a browser-like cache.
I'd like to see fetch requests make use of standard HTTP-caching. That is, honoring Expires, Cache-Control headers, sends If-Modified-Since, and so on.
The text was updated successfully, but these errors were encountered: