Skip to content
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

Caching abstraction treats single method argument as array [SPR-8015] #12670

Closed
spring-issuemaster opened this issue Mar 2, 2011 · 1 comment
Closed
Labels
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Mar 2, 2011

Oliver Drotbohm opened SPR-8015 and commented

Given the following scenario

class SampleClass {

  @Cacheable("mycache")
  public Something getSomething(String id) { ... }

  @CacheEvict(value = "mycache, key = "#id")
  public void updateSomething(String id, Object payload) { ... }
}

cache invalidation will not work correctly. Actually it's not working because the DefaultKeyGenerator simply hashes the given parameters as is. In case no key attribute is configured (just like in the above example) the parameters will be handed in as single-element-Object[] causing a different hash to be created than if the single object would be handed to the key generator directly. So you either have to define the key expression to create an array or alter the annotation on the caching side to @Cacheable(value = "mycache", key = "#id") which is rather repetitive.


Affects: 3.1 M1

Referenced from: commits c3a6351

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 6, 2011

Costin Leau commented

Changed DefaultKeyGenerator implementation to return the object if only one argument is given. This might be somewhat surprising if more params are given but is more intuitive for the majority of cases (when only one param is given) in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.