Spring 3.1 @Cacheable - method still executed

后端 未结 3 805
盖世英雄少女心
盖世英雄少女心 2021-02-01 04:10

I\'m trying to implement Spring 3.1 caching as explained here and here, but it doesn\'t seem to be working: my method is run through every time even though it is marked @cacheab

3条回答
  •  醉话见心
    2021-02-01 04:38

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

    In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual caching at runtime even if the invoked method is marked with @Cacheable - considering using the aspectj mode in this case.

    and

    Method visibility and @Cacheable/@CachePut/@CacheEvict

    When using proxies, you should apply the @Cache annotations only to methods with public visibility.

    1. You self-invoke someMethod in the same target object.
    2. Your @Cacheable method is not public.

提交回复
热议问题