← Questions

Byte-capacity LRU cache that fetches each chunk only once

0
ModalCodingLast asked Sep 2026

Build a cache for chunks of container images pulled over the network, with a capacity measured in bytes. A get(key, size) is a hit when the chunk is cached (refresh its recency), waits when the same chunk is already being fetched (don't start a second download), and otherwise starts one fetch. When a fetch finishes, store the chunk, evicting least recently used chunks until it fits; a chunk bigger than the whole cache is not stored. Only finished chunks take up space. Report which chunks each insert evicts, and talk about how this maps to real concurrent callers.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding