Spring 3.1 Cache Abstraction without parameters

前端 未结 1 1077
抹茶落季
抹茶落季 2021-02-14 20:13

reading about the new Cache Abstraction in Spring 3.1, I wanted to apply this feature to my project.

Can I cache the call to a method that has no parameters?

         


        
1条回答
  •  独厮守ぢ
    2021-02-14 21:09

    You can override this behavior by using "Cache SpEL available metadata" as described here:

    http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/cache.html#cache-spel-context

    In your example, you could specify the following:

    @Cacheable(value = "xCache", key = "#root.methodName") 
    public List loadAllX() { 
        ... 
    } 
    

    Which would cache the list of X in the "xCache" with key "loadAllX"

    0 讨论(0)
提交回复
热议问题