Skip to content

ContainsOrAdd function #17

@estutzenberger

Description

@estutzenberger

The hashicorp lru.Cache implementation (https://github.com/hashicorp/golang-lru/blob/main/lru.go) contains a few other functions which are useful. I'm not sure why they don't include them in the simplelru or expirablelru implementations. In particular, the ContainsOrAdd function which checks for an item and either adds it or returns that it was found without updating recently used information. This is helpful in the case where multiple go routines are using the cache and may have duplicate data. Without such a function, a lock is required around the cache Get + Add operation.

Any plans to add something like this capability or a reason why it doesn't fit with the current implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions