Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
2f49d6d1
Commit
2f49d6d1
authored
Jun 29, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17287 from nosan
* gh-17287: Introduce RedisCacheManagerBuilderCustomizer Closes gh-17287
parents
71b09e39
1d9aae82
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
0 deletions
+61
-0
RedisCacheConfiguration.java
...ork/boot/autoconfigure/cache/RedisCacheConfiguration.java
+2
-0
RedisCacheManagerBuilderCustomizer.java
...toconfigure/cache/RedisCacheManagerBuilderCustomizer.java
+36
-0
CacheAutoConfigurationTests.java
...boot/autoconfigure/cache/CacheAutoConfigurationTests.java
+23
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java
View file @
2f49d6d1
...
...
@@ -56,6 +56,7 @@ class RedisCacheConfiguration {
public
RedisCacheManager
cacheManager
(
CacheProperties
cacheProperties
,
CacheManagerCustomizers
cacheManagerCustomizers
,
ObjectProvider
<
org
.
springframework
.
data
.
redis
.
cache
.
RedisCacheConfiguration
>
redisCacheConfiguration
,
ObjectProvider
<
RedisCacheManagerBuilderCustomizer
>
redisCacheManagerBuilderCustomizers
,
RedisConnectionFactory
redisConnectionFactory
,
ResourceLoader
resourceLoader
)
{
RedisCacheManagerBuilder
builder
=
RedisCacheManager
.
builder
(
redisConnectionFactory
).
cacheDefaults
(
determineConfiguration
(
cacheProperties
,
redisCacheConfiguration
,
resourceLoader
.
getClassLoader
()));
...
...
@@ -63,6 +64,7 @@ class RedisCacheConfiguration {
if
(!
cacheNames
.
isEmpty
())
{
builder
.
initialCacheNames
(
new
LinkedHashSet
<>(
cacheNames
));
}
redisCacheManagerBuilderCustomizers
.
orderedStream
().
forEach
((
customizer
)
->
customizer
.
customize
(
builder
));
return
cacheManagerCustomizers
.
customize
(
builder
.
build
());
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheManagerBuilderCustomizer.java
0 → 100644
View file @
2f49d6d1
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
cache
;
import
org.springframework.data.redis.cache.RedisCacheManager.RedisCacheManagerBuilder
;
/**
* Callback interface that can be used to customize a {@link RedisCacheManagerBuilder}.
*
* @author Dmytro Nosan
* @since 2.2.0
*/
@FunctionalInterface
public
interface
RedisCacheManagerBuilderCustomizer
{
/**
* Customize the {@link RedisCacheManagerBuilder}.
* @param builder the builder to customize
*/
void
customize
(
RedisCacheManagerBuilder
builder
);
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java
View file @
2f49d6d1
...
...
@@ -274,6 +274,17 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
});
}
@Test
public
void
redisCacheWithRedisCacheManagerBuilderCustomizer
()
{
this
.
contextRunner
.
withUserConfiguration
(
RedisWithRedisCacheManagerBuilderCustomizerConfiguration
.
class
)
.
withPropertyValues
(
"spring.cache.type=redis"
,
"spring.cache.redis.time-to-live=15000"
)
.
run
((
context
)
->
{
RedisCacheManager
cacheManager
=
getCacheManager
(
context
,
RedisCacheManager
.
class
);
RedisCacheConfiguration
redisCacheConfiguration
=
getDefaultRedisCacheConfiguration
(
cacheManager
);
assertThat
(
redisCacheConfiguration
.
getTtl
()).
isEqualTo
(
java
.
time
.
Duration
.
ofSeconds
(
10
));
});
}
@Test
public
void
redisCacheWithCustomizers
()
{
this
.
contextRunner
.
withUserConfiguration
(
RedisWithCustomizersConfiguration
.
class
)
...
...
@@ -755,6 +766,18 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
}
@Configuration
(
proxyBeanMethods
=
false
)
@Import
(
RedisConfiguration
.
class
)
static
class
RedisWithRedisCacheManagerBuilderCustomizerConfiguration
{
@Bean
public
RedisCacheManagerBuilderCustomizer
ttlRedisCacheManagerBuilderCustomizer
()
{
return
(
builder
)
->
builder
.
cacheDefaults
(
RedisCacheConfiguration
.
defaultCacheConfig
().
entryTtl
(
java
.
time
.
Duration
.
ofSeconds
(
10
)));
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@Import
({
RedisConfiguration
.
class
,
CacheManagerCustomizersConfiguration
.
class
})
static
class
RedisWithCustomizersConfiguration
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment