Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-8015

Caching abstraction treats single method argument as array

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 3.1 M1
    • Fix Version/s: 3.1 M2
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              costin Costin Leau
              Reporter:
              olivergierke Oliver Gierke
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                7 years, 13 weeks ago