Results 1 to 3 of 3

Thread: Cachable annotation or AOP understanding trouble

  1. #1
    Join Date
    Nov 2010
    Location
    St-Petersburg, Russia
    Posts
    33

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2010
    Location
    St-Petersburg, Russia
    Posts
    33

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •