Skip to content

Add read-only mode to allow cache reads but skip writes#9

Open
cchristous wants to merge 1 commit intorichardartoul:mainfrom
cchristous:cchristous/read-only-mode
Open

Add read-only mode to allow cache reads but skip writes#9
cchristous wants to merge 1 commit intorichardartoul:mainfrom
cchristous:cchristous/read-only-mode

Conversation

@cchristous
Copy link
Contributor

Summary

  • Adds -read-only flag and GOBUILDCACHE_READ_ONLY environment variable to enable read-only mode
  • When enabled, cache reads (GETs) work normally but writes (PUTs) are skipped and return success
  • Useful for feature branches that should pull from cache but not pollute the shared cache

Changes

  • main.go: Added flag, env var support, help text, and startup info message
  • server.go: Added readOnly field, skippedPuts counter, skip logic in handlePut, and fixed pre-existing division-by-zero bugs in stats output when getCount or putCount is zero
  • server_test.go: Added unit tests for read-only mode behavior
  • README.md: Added configuration table entry

Test plan

  • Unit tests pass (go test ./...)
  • Integration tests pass (excluding S3 which requires credentials)
  • Manual testing with GOBUILDCACHE_READ_ONLY=true to verify PUTs are skipped

This enables use cases where you want to pull from the cache but not
populate it, such as running tests on feature branches without
polluting the shared cache.

- Add -read-only flag and GOBUILDCACHE_READ_ONLY env var
- Skip PUT operations when enabled, returning success without writing
- Add skippedPuts counter to stats output
- Fix division-by-zero in stats when getCount or putCount is zero
- Add unit tests for read-only mode behavior
@cchristous cchristous marked this pull request as ready for review February 7, 2026 20:37
duplicateGets, float64(duplicateGets)/float64(getCount)*100)
fmt.Fprintf(os.Stderr, " Deduplicated GETs (singleflight): %d (%.1f%% of GETs)\n",
deduplicatedGets, float64(deduplicatedGets)/float64(getCount)*100)
if getCount > 0 {
Copy link
Owner

Choose a reason for hiding this comment

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

can you remove this conditional so the output is uniform?

if skippedPuts > 0 {
fmt.Fprintf(os.Stderr, " Skipped PUTs (read-only mode): %d\n", skippedPuts)
}
if putCount > 0 {
Copy link
Owner

Choose a reason for hiding this comment

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

same

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