Results 1 to 4 of 4

Thread: AOP: Transaction and Caching

  1. #1
    Join Date
    Jan 2007
    Location
    Kuala Lumpur, Malaysia
    Posts
    138

    Default AOP: Transaction and Caching

    I know function calls to services should be in a transaction.

    but what about caching aspect?

    option A
    "beanServiceTarget" - non proxied service
    "beanServiceTransaction" - a transaction proxy for "beanServiceTarget"
    "beanService" - a cache proxy for "beanServiceTransaction"

    so call to "beanService.findItem(String id)" might not even hit the db and no transaction were ever started.

    option B
    "beanServiceTarget" - non proxied service
    "beanServiceCache" - a cache proxy for "beanServiceTarget"
    "beanService" - a transaction proxy "beanServiceCache"

    so call to "beanService.findItem(String id)" might not even hit the db but a transaction might be started (i'm not sure about this).


    or
    Option C

    "beanDao1Target" - a non-proxied dao
    "beanDao2Target" - a non-proxied dao
    "beanDao1" - a cache proxy for "beanDao1Target"
    "beanDao2" - a cache proxy for "beanDao2Target"
    "beanServiceTarget" - non proxied service, uses "beanDao1" and "beanDao2"
    "beanService" - a transaction proxy "beanServiceCache"

    so call to "beanService.findItem(String id)" might not even hit the db but a transaction might be started (i'm not sure about this). Furthermore, i'm not sure if the dao should be proxied.

    so... any suggestions how i should use cache proxy and transaction proxy together? or is there a cowboy neal way that i haven't figured out yet..

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I'm presuming you aren't using Hibernate otherwise it's much easier . I guess this very much depends on how your application is structured. The Daos are performing the actual data access so it makes sense to proxy them for caching. Obviously as you pointed out you do create a transaction although you never hit the database. I would still personally want the transaction boundary at the service layer.
    Last edited by karldmoore; Aug 29th, 2007 at 11:49 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    I agree with Karl (yet again ) that you still would want your transaction boundary on the service layer. Thus starting a transaction always (which comes in quite handy when using Hibernate ).

    There are already some caching solutions out there which you might want to take a look at.

    Also these links might be interesting to:

    Link
    Link
    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

  4. #4
    Join Date
    Jun 2007
    Posts
    8

    Default

    Hi

    There is another way for caching "static" data (that are rarely updated) : to cache the result of the method that retrieves these data.
    An excellent example is provided in the spring tips website, that proposes a method for Caching methods result using Spring and EHCache

    Nabil

Posting Permissions

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