Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(os/gcache): defaultcache lazy init#4468

Merged
hailaz merged 5 commits intogogf:masterfrom
wanghaolong613:fix/defaultcache-lazyinit
Oct 15, 2025
Merged

fix(os/gcache): defaultcache lazy init#4468
hailaz merged 5 commits intogogf:masterfrom
wanghaolong613:fix/defaultcache-lazyinit

Conversation

@wanghaolong613
Copy link
Contributor

defaultcache更改为懒加载,在用户使用redis缓存时,避免了程序启动时不必要的初始化开销。

image

@hailaz hailaz requested a review from Copilot October 15, 2025 06:27
@hailaz hailaz changed the title Fix/defaultcache lazyinit fix(os/gcache): defaultcache lazy init Oct 15, 2025
Copy link
Contributor

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 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.

@hailaz hailaz merged commit b8e414e into gogf:master Oct 15, 2025
18 checks 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