-
Notifications
You must be signed in to change notification settings - Fork 69
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
cache: Add .Set
and .Add
methods to cache clients
#591
Conversation
8b287e3
to
2f51483
Compare
This change adds a synchronous version of `.Set` to Memcached and Redis clients as well as the various `Cache` wrapper implementations. This allows callers to set a key and be sure it exists in the cache. This change also adds an `.Add` method which conditionally adds an item to the cache only if it does not already exist. This change is a prerequisite for grafana/mimir#9386 Signed-off-by: Nick Pillitteri <[email protected]>
2f51483
to
ebcbf7b
Compare
Proof-of-concept for discussion as part of: #9434 grafana/dskit#591 Signed-off-by: Nick Pillitteri <[email protected]>
Proof-of-concept for discussion as part of: #9434 grafana/dskit#591 Signed-off-by: Nick Pillitteri <[email protected]>
Signed-off-by: Nick Pillitteri <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice one, I'm not sure about the 30d TTL, otherwise LGTM
// When a caller uses the Add method, the presence of absence of an entry in the cache | ||
// has significance. In order to maintain the semantics of that, we only add an entry to | ||
// the LRU when it was able to be successfully added to the shared cache. | ||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't think of this. Can you add a tiny test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, will do 👍
When you give Memcached a TTL longer than 30d, it treats the number of seconds as a Unix timestamp. E.g. if you give it a 31d TTL your item will expire on February 1st 1970 -- immediately. |
Signed-off-by: Nick Pillitteri <[email protected]>
Signed-off-by: Nick Pillitteri <[email protected]>
Signed-off-by: Nick Pillitteri <[email protected]>
Specifically, this pulls in grafana/dskit#591 which adds new `.Set()` and `.Add()` methods to cache interfaces and clients. Signed-off-by: Nick Pillitteri <[email protected]>
Specifically, this pulls in grafana/dskit#591 which adds new `.Set()` and `.Add()` methods to cache interfaces and clients. Signed-off-by: Nick Pillitteri <[email protected]>
What this PR does:
This change adds a synchronous version of
.Set
to Memcached and Redis clients as well as the variousCache
wrapper implementations. This allows callers to set a key and be sure it exists in the cache. This change also adds an.Add
method which conditionally adds an item to the cache only if it does not already exist.Which issue(s) this PR fixes:
This change is a prerequisite for grafana/mimir#9386
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]