Possible to cache ranged requests?

Hi.

I have a worker that acts as a proxy to a protected S3 origin.
Some files, such as audio and video files, will be requested with range requests. If I pass this header to s3 I get a ranged response, and it’s not allowed to store this in the CF cache obviously.

Is it possible with a range request, to fetch the full file from my origin, store using a custom cache key (without range in the key), and then fetch from CF cache with ranged requests later somehow? I’ve tried various ways to do this, and cache api docs is a bit unclear on this to be honest. Anyone tried something similar with a working example?

Kind regards,
Amund

3 Likes

@amund1, we are currently doing this but revisiting it at the moment because we’re having some troubles with it. Were you able to figure it out?

Our solution that’s been working pretty well is to look for cache. If there is no cache, we make two calls to s3. One with the range header removed so we can cache the response and another with the range header included for responding to the client until the full file is cached. Then range requests work when you hit the cache. Not sure if this is the best thing to be doing.