-
Notifications
You must be signed in to change notification settings - Fork 12
Add local memory cache to Redis implementation to reduce roundtrips #1214
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
base: master
Are you sure you want to change the base?
Conversation
Cherry pick to beta success |
Cherry pick to beta success |
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.
Awesome! 💯
| if (_localCache != null) | ||
| _localCache.Set(cacheid, prefix, LocalCacheTTL(LOCAL_CACHE_PERSISTENT_KEY_TTL)); |
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.
You can use null conditional operator to combine the null check with the actual invocation. e.g.
_localCache?.Set(cacheid, prefix, LocalCacheTTL(LOCAL_CACHE_PERSISTENT_KEY_TTL));
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.
Similarly in other places it can be used as well in replacement of checking for non null, and then doing something with the field.
| Task<bool> t = RedisDatabase.KeyExpireAsync(Key(cacheid, key), expiry, flags); | ||
| t.Wait(); | ||
| return t.Result; | ||
| string fullKey = Key(cacheid, key); | ||
| bool expirationSaved = RedisDatabase.KeyExpire(fullKey, expiry, flags); | ||
| if (expirationSaved) | ||
| KeyExpireLocal(fullKey); | ||
| return expirationSaved; | ||
| } | ||
|
|
||
| public bool KeyExists(string cacheid, string key) | ||
| { | ||
| Task<bool> t = RedisDatabase.KeyExistsAsync(Key(cacheid, key)); | ||
| t.Wait(); | ||
| return t.Result; |
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 fixing this async over sync when there was a sync API available!
| private void InitLocalCache() | ||
| { | ||
| #if NETCORE | ||
| if (EnvVarReader.GetEnvironmentValue(GXServices.CACHE_SERVICE, GXServices.REDIS_CACHE_SERVICE, "HYBRID", out string envVarValue) && envVarValue.Equals(true.ToString(), StringComparison.OrdinalIgnoreCase)) |
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.
This is extremely nitpick. Instead of true.ToString() you can use bool.TrueString which doesn't require creating a new string and is already interned.
Cherry pick to beta success |
Cherry pick to beta success |
…the default constructor used by CacheAPI.
Cherry pick to beta success |
Introduced an in-memory local cache in the Redis implementation to cache frequently accessed keys.
Issue:206738