When we read from the cache, we want to keep the buffer the exact right size so we don't waste memory. Right now, we allocate a scratch buffer then swap the contents, and that's going to waste memory because the scratch buffer might be quite a bit larger than necessary.
Put a malloc call back into the read path.