Announcement Announcement Module
Collapse
No announcement yet.
Cachable annotation or AOP understanding trouble Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cachable annotation or AOP understanding trouble

    Hello!

    I'm not sure that I've chosen the correct forum to ask this question -- sorry for that.

    I'm using the @Cacheable annotation on the method and it works well:

    Code:
        @Override
        @Cacheable("menu")
        public Menu getFullMenu(Consumer consumer) {
             // Some expensive work here
        }
    This method is described in some MenuProvider interface. Implementation defined in the context file. I'm accessing it like this:
    Code:
    Consumer consumer = ...;
    MenuProvider menuProvider = classPathXmlApplicationContext.getBean("menuProvider", MenuProvider.class);
    Menu menu = menuProvider.getFullMenu(consumer);
    But it does not work when I move the Cacheable annotation to another method like this:
    Code:
        @Override
        public Menu getFullMenu(Consumer consumer) {
             return getFullMenuInternal(consumer);
        }
    
        @Cacheable("menu")
        public Menu getFullMenuInternal(Consumer consumer) {
             // Some expensive work here
        }
    I understand that internal method must be public, but it seems that I missing something else (about AOP or about @Cacheable).

    Any ideas?

    Regards,
    Alexey?

  • #2
    I suggest a read of the reference guide especially the AOP chapter/part about explaining proxies.

    Only EXTERNAL method calls pass through a proxy so that AOP can be applied INTERNAL method calls don't pass through the proxy and as such AOP isn't applied.

    If you want to make this work you have to switch to either loadtime- or compile time weaving.

    Comment


    • #3
      Thank you Marten for detailed explanation! It's exactly my case.

      Comment

      Working...
      X