Skip to content

Improve toString representation of complex parameters in SimpleKey #27670

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

Closed
wants to merge 2 commits into from

Conversation

asgh
Copy link
Contributor

@asgh asgh commented Nov 11, 2021

Arrays.deep* is being used in all the other functions, use it in toString as well - this avoids debugging output that just looks like [Ljava.lang.Object;@123456

asgh added 2 commits November 10, 2021 20:12
Arrays.deep* is being used in all the other functions, use it in toString as well - this avoid debugging output that just looks like [Ljava.lang.Object;@123456
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 11, 2021
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 11, 2021
@snicoll snicoll changed the title use Arrays.deepToString for toString in SimpleKey Improve toString representation of complex parameters in SimpleKey Aug 26, 2023
@snicoll snicoll self-assigned this Aug 26, 2023
@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 26, 2023
@snicoll snicoll added this to the 6.1.0-RC1 milestone Aug 26, 2023
snicoll pushed a commit that referenced this pull request Aug 26, 2023
@snicoll snicoll closed this in 7c508a4 Aug 26, 2023
@snicoll
Copy link
Member

snicoll commented Aug 26, 2023

Very nice @asgh. Thank you for making your first contribution to Spring Framework.

@MitrichDa
Copy link

@asgh It changed keys generated in @cacheble. It can affect projects with multiple services and distributed cache

@asgh
Copy link
Contributor Author

asgh commented Feb 19, 2025

@MitrichDa

@asgh It changed keys generated in @cacheble. It can affect projects with multiple services and distributed cache

You have multiple servers running apps using different version of spring? Seems risky to me, but still wouldn't it just mean some things are cached twice? Or are you doing complex cache invalidation?

Are you really sure that @cachable is using the toString() version of a key to determine equality for caching? Something tells me that's not what's happening.

@MitrichDa
Copy link

@asgh Microservices with redis distributed cache, yes, and not all of them update spring version simultaneously.

@Cacheable(cacheNames = "test-cache")
public String myMethod(String test1, String test2) {
// Method logic
}
myMethod("test1", "test2");

will result with key in redis test-cache::SimpleKey [test1, test2] or test-cache::SimpleKey [test1,test2] depending on version

@bclozel
Copy link
Member

bclozel commented Feb 19, 2025

@MitrichDa I'm afraid it is too late to consider reverting that change. Spring Framework 6.1 has been out for a while and is almost out of open source support. Spring Framework 6.2 is also using the same algorithm, so changing it back will disrupt you more.

I would suggest updating your cache keys to using a more predictable value if you wish to use a cache with various Spring Framework minor versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants