-
Notifications
You must be signed in to change notification settings - Fork 200
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
Redis cache impl #954
Redis cache impl #954
Conversation
Codecov Report
@@ Coverage Diff @@
## main #954 +/- ##
==========================================
- Coverage 81.18% 79.53% -1.66%
==========================================
Files 19 17 -2
Lines 1802 1798 -4
==========================================
- Hits 1463 1430 -33
- Misses 268 296 +28
- Partials 71 72 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. |
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.
LGTM! Left a few questions, found a typo or 2, but the core functionality looks great--this is an awesome new feature!
I don't have a lot of familiarity with the flag evaluation/middleware parts of the code yet, but looked good from my understanding.
🚀
TTL: 1 * time.Minute, | ||
Memory: MemoryCacheConfig{ | ||
Enabled: false, | ||
Expiration: -1, | ||
EvictionInterval: 10 * time.Minute, | ||
EvictionInterval: 5 * time.Minute, |
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.
Clarification: TTL replaces expiration here and expiration + evicition interval are a gocache
paradigm? The Redis cache accepts TTL and uses it to refresh the cache when there's a read + TTL expiration?
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.
TTL replaces expiration here and expiration
Yeah so TTL = expiration from go-cache terminology
. Previously the default config used -1
for expiration which meant items never expired automatically. Since now we are more heavily reliant on TTL since we're moving the caching logic up a layer, I figured it made sense to set a 'sane' 1m default instead across the board.
evicition interval are a gocache paradigm
Yeah. go-cache
lets you set how often the 'cleanup' routine runs to deleted expired items from the cache, unlike redis (see below) which seems to manage this process it self
Redis cache accepts TTL and uses it to refresh the cache when there's a read + TTL expiration
Yeah so when we go to read from Redis and it sees that the TTL has expired it acts as a 'miss' and so we go read from the DB and then repopulate the cache item. Redis randomly also deletes expired items from the redis db to clear space, but it doesnt auto-repopulate the cache itself: https://redis.io/commands/expire/#how-redis-expires-keys
@@ -160,10 +202,17 @@ func Default() *Config { | |||
}, | |||
|
|||
Cache: CacheConfig{ | |||
Enabled: false, | |||
Backend: CacheMemory, | |||
TTL: 1 * time.Minute, |
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.
Do you know if redis allows negative TTLs like in-memory cache?
Question behind the question: do you generally want to defer to the underlying library for configuration validation?
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 question. looking at the lib it seems to return 0 if the TTL is < 0
In general I think we do do more validation on the config after parsing. There is currently minimal validation happening on the config after parsing. IIRC its mostly to catch issues that the libraries used do not like, like passing an empty DB url to the underlying stdlib DB adapters.
We should prob come up with some kind of 'rule' to figure out what we validate and what we dont
Co-authored-by: Thomas Sickert <thomas.sickert@gmail.com>
Fixes: #633 (kind of)
Major Changes
cache.memory.enabled
andcache.memory.expiration
Accept: application/json+pretty
header)Caching Strategy
Flags
Evaluation
Files to 👀
These are the main files that have major changes that I would love some eyes on in this review