This is a classic time vs. space tradeoff. There is no universal answer, just good practice to get an answer.
Rules of thumb:
Disk IO is slow. Decryption and/or decompression consume cycles. Avoiding repeated work of this type generally makes programs go faster.
But buffering requires RAM. RAM is a limited resource. Use of RAM loads the processor cache. Very heavy use of RAM loads the VM system. Both cause slow-downs that partially defeat the avoidance of disk I/O. In the extreme, loading the VM system causes swapping to/from disk, so the buffering is causing Disk IO.
After the rules of thumb are done, you must use good engineering practice.
- Determine how much memory you can dedicate to holding disk data in memory.
- Determine which structures are read repeatedly from disk and how often.
- Determine their sizes.
Choose a set that makes sense: those with the highest value of
(IO time per byte + Decompress/decrypt Time per byte) x FrequencyOfReads x Size in bytes
that also fit in available RAM.
Implement caching of 4. as you have proposed.
- Profile and measure. Try alternatives. Repeat as needed.