...
Presuming the range information would be stored in the root segment, memory bounding may not be necessary. This data is rewritten frequently in normal operation, such as for a refresh or the addition of an alternate. If we are willing to do a rewrite for a range request then we can have much weaker space bounds on the memory consumed by the range tracking. This would require a read from disk on a cache hit but that is commonly done now. The key difference would be treating a cache "miss" differently, although the mechanism used for an alternate miss may work as well.
Plugin Implementation
An alternative to modifying the cache is to implement a partial object caching plugin on top of the existing cache. The fundamental idea here is that the plugin fetches fixed-size "chunks" from the origin and uses those to compose the range requested by the client. For each client request, the plugin
- determines the set of chunks that overlap the range
- issues a new set of origin requests (in parallel) to fetch the corresponding chunks
- rewrites the cache key for each chunk so they are all stored independently
- creates a transformed client response by composing the correct byte ranges from the chunks
This would be a fairly complex plugin, but it has the advantage of not changing the cache format and minimizes the risk of breaking other features.