Jul 19th, 2011, 08:32 AM
Conditionally applying aspects (ehcache + transactions)
I'm using EHCache to cache some methods in my service. When executing those methods, if EHCache finds their results in its cache, should *NOT* be transactional. Instead, if EHCache does not find their results in the cache, they *SHOULD* be transactional.
The fact is that when applying aspects (using @Transactional and @Cacheable annotations), what is really happening is that my classes are being wrapped (proxied), and so when I'm applying two aspects they are proxied twice, that is, first a proxy is created around my bean and then another proxy on the first one. So: isn't there a way to tell one of them to apply its wrapping code only if the first one didn't apply (in configuration, not touching code)? Or even to tell one of them not to proxy my bean at all?
I think it would be desirable to provide the proxies with something like a chain of responsibility or similar, to propagate the proxied behavior depending on the result of previous links in the chain.
Thank you in advance
Tags for this Thread