-
-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
Feature Request: GetOrSetFunc
Support for lazy initialization e.g.: for an IP based rate limiter implementation:
I want to be able to do this:
rateLimitForIP, _ := st.rateLimiters.GetOrSetFunc(
ip,
func() *rate.Limiter { return rate.NewLimiter(st.rateLimit, 1) },
gcache.WithExpiration(itemTTL),
)
So that I can avoid doing this:
rateLimitForIP, _ := st.rateLimiters.GetOrSet(
ip,
rate.NewLimiter(st.rateLimit, 1),
gcache.WithExpiration(itemTTL),
)
Because rate limiter object is heavy and will generate pressure on the garbage collector for not-set items.
Metadata
Metadata
Assignees
Labels
No labels