Skip to content

feat: add a cache for compressed binaries#21919

Merged
spikecurtis merged 1 commit intomainfrom
spike/internal-1300-bin-handler-uses-cachecompress
Feb 6, 2026
Merged

feat: add a cache for compressed binaries#21919
spikecurtis merged 1 commit intomainfrom
spike/internal-1300-bin-handler-uses-cachecompress

Conversation

@spikecurtis
Copy link
Contributor

@spikecurtis spikecurtis commented Feb 4, 2026

Relates to: coder/internal#1300

Adds the cachecompress.Compressor to the binary handler.

Copy link
Contributor

@coder-tasks coder-tasks bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/ and orig/ subdirectories
  • Wraps binary file server with cachecompress.Compressor when cache directory is provided
  • Falls back to plain http.FileServer when no cache directory exists (testing scenarios)
  • Updates binHandler to use generic http.Handler instead of concrete http.FileSystem
  • Updates comment to reflect new orig/ subdirectory path

Issues to Address

  1. Missing dependency documentation (line 25): This PR depends on the cachecompress package which doesn't exist on main branch yet. The PR description should explicitly document which PR introduces it and the merge order dependency.

  2. Undocumented constant (line 28): CompressionLevel is 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
  3. 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
  4. 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-Encoding headers
    • Fallback to uncompressed serving when cache dir is empty
    • Cache directory structure created correctly (compressed/ and orig/ 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

@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from ebd11cb to 9219451 Compare February 4, 2026 10:11
@spikecurtis spikecurtis force-pushed the spike/internal-1300-site-takes-cache-dir branch from 174915d to 55ff2fc Compare February 4, 2026 10:11
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from 9219451 to 8106a6c Compare February 4, 2026 10:19
@spikecurtis spikecurtis force-pushed the spike/internal-1300-site-takes-cache-dir branch from 55ff2fc to f220d00 Compare February 4, 2026 10:19
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch 2 times, most recently from 5c4a495 to e33ee3d Compare February 4, 2026 11:50
@spikecurtis spikecurtis force-pushed the spike/internal-1300-site-takes-cache-dir branch from f220d00 to 69d8817 Compare February 4, 2026 11:50
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from e33ee3d to 2a1bb80 Compare February 4, 2026 11:50
@spikecurtis spikecurtis force-pushed the spike/internal-1300-site-takes-cache-dir branch from 69d8817 to aa754c2 Compare February 4, 2026 11:50
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from 2a1bb80 to e34610b Compare February 5, 2026 08:46
@spikecurtis spikecurtis force-pushed the spike/internal-1300-site-takes-cache-dir branch from aa754c2 to 937a341 Compare February 6, 2026 06:14
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from e34610b to 7a87b89 Compare February 6, 2026 06:15
@spikecurtis spikecurtis force-pushed the spike/internal-1300-site-takes-cache-dir branch from 937a341 to 1c048ce Compare February 6, 2026 06:31
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from 7a87b89 to df7270f Compare February 6, 2026 06:31
@graphite-app graphite-app bot changed the base branch from spike/internal-1300-site-takes-cache-dir to graphite-base/21919 February 6, 2026 06:42
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from df7270f to c01ae30 Compare February 6, 2026 06:57
@graphite-app graphite-app bot changed the base branch from graphite-base/21919 to main February 6, 2026 06:58
@spikecurtis spikecurtis force-pushed the spike/internal-1300-bin-handler-uses-cachecompress branch from c01ae30 to 3f6e16d Compare February 6, 2026 06:58
@spikecurtis spikecurtis merged commit 15885f8 into main Feb 6, 2026
28 of 29 checks passed
Copy link
Contributor Author

Merge activity

@spikecurtis spikecurtis deleted the spike/internal-1300-bin-handler-uses-cachecompress branch February 6, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants