Skip to content

Improve RedisCacheManagerBuilder to expose applied RedisCacheConfiguration #2583

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented May 18, 2023

Before this commit, we need reflection if we want customization base on applied RedisCacheConfiguration, it's not conventional.

Take spring-boot RedisCacheManagerBuilderCustomizer for example:

	@Bean
	@ConditionalOnClass(name = "org.springframework.data.redis.cache.RedisCacheConfiguration")
	RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() {
		return builder -> {
			RedisCacheConfiguration oldDefaultCacheConfiguration = ReflectionUtils.getFieldValue(builder,
					"defaultCacheConfiguration");
			RedisCacheConfiguration newDefaultCacheConfiguration = oldDefaultCacheConfiguration
				.serializeValuesWith(SerializationPair.fromSerializer(new CompactJdkSerializationRedisSerializer()));
			builder.cacheDefaults(newDefaultCacheConfiguration);
		};
	}

after this commit, it could be:

	@Bean
	@ConditionalOnClass(name = "org.springframework.data.redis.cache.RedisCacheConfiguration")
	RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() {
		return builder -> {
			builder.cacheDefaults(builder.cacheDefaults()
				.serializeValuesWith(SerializationPair.fromSerializer(new CompactJdkSerializationRedisSerializer())));
		};
	}

…ation

before this commit, we need reflection if we want customization base on applied RedisCacheConfiguration, it's not conventional.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 18, 2023
@jxblum jxblum self-requested a review May 18, 2023 23:51
@jxblum jxblum self-assigned this May 18, 2023
@jxblum jxblum added in: cache RedisCache and CacheManager type: enhancement A general enhancement labels May 18, 2023
@jxblum jxblum added this to the 3.0.7 (2022.0.7) milestone May 18, 2023
jxblum added a commit to jxblum/spring-data-redis that referenced this pull request May 19, 2023
Additionally, refactors and cleans up the Redis cache extension and infrastructure.

Closes spring-projects#2583
jxblum pushed a commit to jxblum/spring-data-redis that referenced this pull request May 19, 2023
…ation.

Now it is possible to construct a new, custom default RedisCacheConfiguration from an existing, default RedisCacheConfiguration.

This is useful in a Spring Boot context using the RedisCacheManagerBuilderCustomizer and acquiring access to the default RedisCacheConfiguration, which likely originated from Spring Boot Redis CacheProperties.

Resolves spring-projects#2583
jxblum added a commit to jxblum/spring-data-redis that referenced this pull request May 19, 2023
Additionally, refactors and cleans up the Redis cache extension and infrastructure.

Closes spring-projects#2583
jxblum pushed a commit to jxblum/spring-data-redis that referenced this pull request May 19, 2023
…ation.

Now it is possible to construct a new, custom default RedisCacheConfiguration from an existing, default RedisCacheConfiguration.

This is useful in a Spring Boot context using the RedisCacheManagerBuilderCustomizer and acquiring access to the default RedisCacheConfiguration, which likely originated from Spring Boot Redis CacheProperties.

Resolves spring-projects#2583
jxblum added a commit to jxblum/spring-data-redis that referenced this pull request May 19, 2023
Additionally, refactors and cleans up the Redis cache extension and infrastructure.

Closes spring-projects#2583
@jxblum jxblum removed the status: waiting-for-triage An issue we've not yet triaged label May 19, 2023
@jxblum jxblum closed this in 9f98f0d May 19, 2023
@jxblum
Copy link
Contributor

jxblum commented May 19, 2023

Thank you for the contribution. This has been reviewed, polished and merged in main (for 3.2.x), 3.1.x and 3.0.x.

However, I am not certain that I will back port this change to SD Redis 2.7.x.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: cache RedisCache and CacheManager type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants