Skip to content

feat: add block-level caching for ByteSource#7

Merged
jmgilman merged 2 commits into
masterfrom
feat/block-cache
Jan 17, 2026
Merged

feat: add block-level caching for ByteSource#7
jmgilman merged 2 commits into
masterfrom
feat/block-cache

Conversation

@jmgilman
Copy link
Copy Markdown
Contributor

Summary

  • Adds block-level caching for ByteSource to optimize random access reads from remote sources
  • Adds cache size management (limits, pruning) to the existing disk cache
  • Adds comprehensive documentation for both features

Block Cache

New BlockCache interface wraps ByteSource with fixed-size block caching:

  • Disk-backed implementation with configurable block size (default 64KB)
  • MaxBlocksPerRead bypass prevents caching large sequential reads (e.g., CopyDir)
  • LRU-style pruning by modification time when size limit exceeded
  • Singleflight deduplication for concurrent block fetches
  • SourceID() method on ByteSource provides stable cache key generation

Cache Size Management

Extended Cache interface with size tracking and pruning:

  • WithMaxBytes option sets cache size limit
  • MaxBytes(), SizeBytes() for monitoring
  • Prune(targetBytes) for manual eviction

Documentation

  • New guide: docs/guides/block-caching.md
  • Updated caching.md with cache size management section
  • Updated performance-tuning.md with block cache tuning
  • Updated API reference with all new interfaces and options

Test plan

  • Run just ci to verify linting and tests pass
  • Run block cache benchmarks: go test -bench=BlockCache -run=^$ ./...
  • Build docs: cd docs && npm run build
  • Preview docs: cd docs && npm run start

🤖 Generated with Claude Code

Adds a new block cache that caches fixed-size blocks from ByteSources,
optimizing random access reads from remote sources. Key features:

- BlockCache interface wraps ByteSource with block-level caching
- Disk-backed implementation with configurable block size (default 64KB)
- MaxBlocksPerRead bypass prevents caching large sequential reads
- LRU-style pruning by modification time
- Singleflight deduplication for concurrent block fetches
- SourceID method on ByteSource for stable cache key generation

Also adds cache size management to existing disk cache:
- WithMaxBytes option for size limits
- MaxBytes(), SizeBytes(), Prune() methods on Cache interface

Documentation updated with block caching guide, cache pruning docs,
and API reference for all new interfaces and options.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jan 17, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
blob d11bdca Commit Preview URL

Branch Preview URL
Jan 17 2026, 09:10 PM

- Add nolint comment for intentionally ignored writeBlock error
- Add nolint comment for safe file read from hash-derived path
- Add nolint comments for validated int64->uint64 conversions
- Combine parameter types in pruneDir signature (gocritic)
- Use string concatenation instead of fmt.Sprintf (perfsprint)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jmgilman jmgilman merged commit 8fc2eef into master Jan 17, 2026
2 checks passed
@jmgilman jmgilman deleted the feat/block-cache branch January 17, 2026 21:18
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.

1 participant