Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add option to get list of keys #42

Closed
tfonfara opened this issue Apr 6, 2021 · 3 comments
Closed

Feature request: Add option to get list of keys #42

tfonfara opened this issue Apr 6, 2021 · 3 comments

Comments

@tfonfara
Copy link
Contributor

tfonfara commented Apr 6, 2021

Currently I have to know (by key) which cache entry I want to remove. My use case is that at some event multiple keys should get invalidated (e.g. all keys with prefix xy). Currently I can maintain my own list of keys using SetNewItemCallback and SetExpirationReasonCallback but as I would have to deal with concurrency there as well I would love to see something similar in this library!

Untested draft:

func (cache *Cache) GetKeys() ([]string, error) {
    cache.mutex.Lock()
    if cache.isShutDown {
        cache.mutex.Unlock()
        return nil, ErrClosed
    }

    keys := make([]string, len(cache.items))
    i := 0
    for k := range cache.items {
        keys[i] = k
        i++
    }

    cache.mutex.Unlock()

    return keys, nil
}
@tfonfara
Copy link
Contributor Author

tfonfara commented Apr 8, 2021

Added PR #43

ReneKroon pushed a commit that referenced this issue Apr 8, 2021
@ReneKroon
Copy link
Contributor

The MR is good, it's failing coverage but that's because of another small thing i merged on master recently. You can use master if you like. I'll clean up the build and release a full version within roughly a week.

@tfonfara
Copy link
Contributor Author

tfonfara commented Apr 8, 2021

Thanks, sounds good!

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

No branches or pull requests

2 participants