fix(os/gcache): defaultcache lazy init#4468
Merged
hailaz merged 5 commits intogogf:masterfrom Oct 15, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR lazily initializes the default gcache instance to avoid unnecessary startup overhead (especially when using Redis), and adds interface-implementation assertions plus benchmarking for the change.
- Switch default cache to lazy init via sync.OnceValue and update all top-level helpers accordingly
- Add benchmarks comparing old eager init vs new lazy init
- Add compile-time interface assertions for adapters and test provider; minor test wait simplification
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| os/gcache/gcache.go | Replace eager defaultCache with lazy sync.OnceValue and update all wrapper functions to call defaultCache() |
| os/gcache/gcache_z_bench_test.go | Add benchmarks and helpers to compare old vs new default cache initialization behavior |
| os/gcache/gcache_z_unit_test.go | Replace select with time.After by simpler time.Sleep in concurrency test waits |
| os/gcache/gcache_adapter_memory.go | Add interface assertion for AdapterMemory |
| os/gcache/gcache_adapter_redis.go | Add interface assertion for AdapterRedis |
| net/ghttp/ghttp_z_unit_feature_middleware_basic_test.go | Use idiomatic interface assertion form for testTracerProvider |
| contrib/registry/zookeeper/zookeeper.go | Use idiomatic interface assertion form for Registry |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
…/gf into fix/defaultcache-lazyinit
hailaz
approved these changes
Oct 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
defaultcache更改为懒加载,在用户使用redis缓存时,避免了程序启动时不必要的初始化开销。