Skip to content

Feature Request: GetOrSetFunc #68

@adrianosela

Description

@adrianosela

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions