feat: add a cache for compressed binaries#21919
Conversation
There was a problem hiding this comment.
Code Review
Reviewed PR adding compressed binary caching. The implementation integrates cachecompress.Compressor to serve binaries with on-demand compression and caching.
Summary of Changes
- Splits cache directory into
compressed/andorig/subdirectories - Wraps binary file server with
cachecompress.Compressorwhen cache directory is provided - Falls back to plain
http.FileServerwhen no cache directory exists (testing scenarios) - Updates
binHandlerto use generichttp.Handlerinstead of concretehttp.FileSystem - Updates comment to reflect new
orig/subdirectory path
Issues to Address
-
Missing dependency documentation (line 25): This PR depends on the
cachecompresspackage which doesn't exist on main branch yet. The PR description should explicitly document which PR introduces it and the merge order dependency. -
Undocumented constant (line 28):
CompressionLevelis exported but lacks a doc comment. Should explain why level 5 was chosen:// CompressionLevel is the gzip/deflate compression level used for binary caching. // Level 5 provides a good balance between compression ratio and CPU usage. const CompressionLevel = 5
-
Inconsistent terminology (line 105): Error comment uses "cached dir" but elsewhere uses "cache dir". Should be consistent:
// cache dir was provided, but we can't write to it -
Missing test coverage: No tests verify the new caching behavior. Should add tests for:
- Binary files are compressed and cached correctly
- Compressed files served with proper
Content-Encodingheaders - Fallback to uncompressed serving when cache dir is empty
- Cache directory structure created correctly (
compressed/andorig/subdirs) - Error handling when cache directory creation fails
Positive Notes
- ✅ Error handling properly wraps errors with
xerrors.Errorf - ✅ Secure file permissions (0o700 for directories)
- ✅ Good fallback behavior for testing scenarios
- ✅ Import organization follows Go conventions
- ✅ Clear comment explaining ExtractOrReadBinFS behavior with empty cacheDir
ebd11cb to
9219451
Compare
174915d to
55ff2fc
Compare
9219451 to
8106a6c
Compare
55ff2fc to
f220d00
Compare
5c4a495 to
e33ee3d
Compare
f220d00 to
69d8817
Compare
e33ee3d to
2a1bb80
Compare
69d8817 to
aa754c2
Compare
2a1bb80 to
e34610b
Compare
aa754c2 to
937a341
Compare
e34610b to
7a87b89
Compare
937a341 to
1c048ce
Compare
7a87b89 to
df7270f
Compare
1c048ce to
6b1adb8
Compare
df7270f to
c01ae30
Compare
c01ae30 to
3f6e16d
Compare
Merge activity
|

Relates to: coder/internal#1300
Adds the
cachecompress.Compressorto the binary handler.