Skip to content

Conversation

@molon
Copy link
Collaborator

@molon molon commented Nov 15, 2025

This pull request updates documentation and example code to clarify and improve the explanation of cache stampede protection, cache write propagation, and resource management in the Cachex library. The changes focus on both the English and Chinese README files, code examples, and benchmarking setup. The most important updates are grouped below:

Documentation and Conceptual Improvements:

  • Expanded the explanation of cache stampede protection in both README.md and README_ZH.md to describe the new "Singleflight + DoubleCheck" mechanism, detailing how concurrent requests are deduplicated and edge cases are eliminated. [1] [2] [3] [4] [5] [6]
  • Improved the architecture diagrams and sequence diagrams to show accurate cache and not-found cache update flows, including explicit delete and set operations for both caches. [1] [2] [3] [4] [5] [6]

Resource Management in Examples:

  • Added defer ...Close() statements to all cache and client initializations in code examples, ensuring proper resource cleanup in both English and Chinese documentation. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

Multi-Level Cache Write Propagation:

  • Added new documentation sections explaining how write operations (Set/Del) automatically propagate through cache layers when a Client is used as an upstream, supporting both write-through and cache-aside patterns. [1] [2]

Benchmarking Improvements:

  • Updated benchmark_test.go to clean up the client resource after each benchmark scenario by calling client.Close() in a cleanup function.

Configuration Updates:

  • Changed the Go test coverage configuration in .vscode/settings.json to use the correct package path for coverage analysis.

Copilot AI review requested due to automatic review settings November 15, 2025 14:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a comprehensive improvement to cache stampede protection by adding a "DoubleCheck" optimization mechanism that works alongside the existing Singleflight approach. The changes include new BigCache integration for tracking recent writes, enhanced error messages across all cache implementations, proper resource cleanup patterns, and extensive documentation updates in both English and Chinese README files.

Key changes:

  • Introduced DoubleCheck mechanism with configurable time windows to eliminate race conditions in concurrent cache access
  • Added BigCache as a new cache backend, primarily used for tracking recently written keys
  • Enhanced all cache implementations with detailed error context including key information
  • Added Client.Close() method for proper resource cleanup
  • Improved write operation propagation through multi-level cache architectures

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
client.go Added double-check optimization, Close() method, write propagation logic, and panic recovery
double_check.go New file implementing double-check mechanism with timestamp compression
double_check_test.go Comprehensive tests for double-check functionality and race window scenarios
bigcache.go New BigCache implementation for []byte values
bigcache_test.go Basic tests for BigCache operations
ristretto.go Updated error handling and Close() signature
redis.go Enhanced error messages with key context
gorm.go Enhanced error messages with key context
client_test.go Added resource cleanup and new test cases
entry_test.go Added defer client.Close()
benchmark_test.go Added client cleanup in benchmark
.vscode/settings.json Corrected package path for coverage
.gitignore Added .vscode to ignore list
go.mod/go.sum Added bigcache dependency
README.md/README_ZH.md Updated documentation with double-check explanation and defer patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@molon molon merged commit 61ed91c into main Nov 15, 2025
1 check passed
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