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

Allow dynamic values in @Cacheable and @CacheEvict

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 3.1.4
    • Fix Version/s: None
    • Component/s: Caching
    • Last commented by a User:
      false

      Description

      @Cacheable and @CacheEvict only take a constant value for the cache names. Allow it to be a dynamic value: class field, value from properties file eg $

      {myProperty}

      like in @Value or a SpEL expression.

      In case of abstract classes that implement methods that should be cached but each subclass should use a different cache name. This is not possible currently and hence such methods can not be put into an abstract class even though all subclasses use exactly the same method.

        Activity

        Hide
        snicoll Stéphane Nicoll added a comment -

        The cache abstraction supports the CacheResolver abstraction now and it can be specified globally, per class and/or on a specific operation. The CacheResolver give you the ability to compute the caches to use in code so you have all the flexibility that you want.

        Show
        snicoll Stéphane Nicoll added a comment - The cache abstraction supports the CacheResolver abstraction now and it can be specified globally, per class and/or on a specific operation. The CacheResolver give you the ability to compute the caches to use in code so you have all the flexibility that you want.

          People

          • Assignee:
            snicoll Stéphane Nicoll
            Reporter:
            beginner_ Thomas Struntz
            Last updater:
            Stéphane Nicoll
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 9 weeks, 5 days ago