-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Improve cache auto-configuration for Redis #10944
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
Conversation
Expose key prefix, TTL and null value settings for spring-data-redis' RedisCacheConfiguration in Spring .properties/yml configuration files. Example: spring.cache.redis.ttl=PT15M spring.cache.redis.keyPrefix=foo spring.cache.redis.useKeyPrefix=false spring.cache.redis.cacheNullValues=false Fixes gs-10795
Addresses this |
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.
Thank you so much for your first contribution to Spring Boot. I've made a few suggestions, can you please have a look to them?
You can squash and push force on your existing branch or just push an additional commit with your changes.
public static class Redis { | ||
|
||
/** | ||
* The TTL for entries. By default, entries do not expire, a value of zero |
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.
Configuration key descriptions do not start with The
, A
, etc. Please look at existing keys for inspiration
* The TTL for entries. By default, entries do not expire, a value of zero | ||
* indicates an eternal entry, and the given value will be converted to seconds.. | ||
* | ||
* @see Duration#parse(CharSequence) |
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.
We don't make such @see
link here. We use the javadoc to infer the description. Can you please remove them all?
private boolean cacheNullValues = true; | ||
|
||
/** | ||
* The non-null Redis key prefix to use instead of the default one. |
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 am not sure what you mean by "non-null" here.
return this; | ||
} | ||
|
||
public Optional<String> getKeyPrefix() { |
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.
Configuration properties must be JavaBean properties (the type must match) and we don't support Optional
here.
@@ -57,13 +59,38 @@ | |||
|
|||
@Bean | |||
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { | |||
|
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.
Please refrain from making unnecessary formatting changes.
RedisCacheManagerBuilder builder = RedisCacheManager | ||
.builder(redisConnectionFactory); | ||
.builder(redisConnectionFactory).cacheDefaults(getConfiguration()); | ||
|
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.
Idem
List<String> cacheNames = this.cacheProperties.getCacheNames(); | ||
if (!cacheNames.isEmpty()) { | ||
builder.initialCacheNames(new LinkedHashSet<>(cacheNames)); | ||
} | ||
|
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.
Idem
* Remove unnecessary formatting changes * Discontinue use of Optional for Redis property configuration * Remove @see tags * Change verbiage for property descriptions Fixes gs-10795
Thanks so much for the detailed feedback, @snicoll; I hope that the follow-up commit has addressed your concerns! I'm happy to be able to give back in some small way to a project that I've used so much throughout my career. |
* pr/10944: Polish "Improve cache auto-configuration for Redis" Improve cache auto-configuration for Redis Respond to MR feedback Improve spring-boot-autoconfigure for Redis caches
@ryonday Thanks for the feedback. They did partially and I had an extra polish pass. It's now merged in |
Thanks so much for the polish pass, I have a few more small PR ideas and it helps to have a template for the preferred conventions and style to make it easier on reviewers! Cheers! |
Expose key prefix, TTL and null value settings for spring-data-redis' RedisCacheConfiguration in Spring .properties/yml configuration files.
Example:
Fixes gs-10795