micro--go-micro
2869cc16d1
* Initial plan * Add adaptive throttling to prevent cache penetration without stale cache Implement rate limiting mechanism to protect etcd when: - Cache is empty (no stale data available) - Registry is failing/overloaded - Multiple sequential requests arrive Changes: - Add MinimumRetryInterval option (default 5s) - Track last failed attempt time per service - Throttle requests within retry interval when no cache exists - Clear throttling on successful lookup - Add comprehensive tests validating throttling behavior Co-authored-by: asim <17530+asim@users.noreply.github.com> * Fix WaitGroup race condition in events stream tests The WaitGroup.Add() calls were happening after goroutines started, causing a race where Done() could be called before Add(), resulting in "negative WaitGroup counter" panics. Fixes: - Move wg.Add(1) before goroutine in TestConsumeTopic - Move wg.Add(2) before first goroutine in TestConsumeGroup Co-authored-by: asim <17530+asim@users.noreply.github.com> * Update registry cache documentation with adaptive throttling feature Document the new adaptive throttling feature that prevents cache penetration when registry is failing and no stale cache exists. Includes: - Feature overview - Usage examples with configuration options - Explanation of throttling behavior - Example scenario demonstrating protection Co-authored-by: asim <17530+asim@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: asim <17530+asim@users.noreply.github.com>
30 行
593 B
Go
30 行
593 B
Go
package cache
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go-micro.dev/v5/logger"
|
|
)
|
|
|
|
// WithTTL sets the cache TTL.
|
|
func WithTTL(t time.Duration) Option {
|
|
return func(o *Options) {
|
|
o.TTL = t
|
|
}
|
|
}
|
|
|
|
// WithLogger sets the underline logger.
|
|
func WithLogger(l logger.Logger) Option {
|
|
return func(o *Options) {
|
|
o.Logger = l
|
|
}
|
|
}
|
|
|
|
// WithMinimumRetryInterval sets the minimum retry interval for failed lookups.
|
|
// This prevents cache penetration when registry is failing and there's no stale cache.
|
|
func WithMinimumRetryInterval(d time.Duration) Option {
|
|
return func(o *Options) {
|
|
o.MinimumRetryInterval = d
|
|
}
|
|
}
|