qianjava / ehcache-spring-annotations

Automatically exported from code.google.com/p/ehcache-spring-annotations
0 stars 0 forks source link

Added postConditionBeanName attribute to Cacheable annotation #60

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
I added a functionality to the cacheable that i needed that is an attribute on 
the Cacheable annotation like this

@Cacheable(postConditionBeanName="postConditionEvaluator")

The idea is that after returning from the method, in the interceptor, this bean 
is called  with the return value of the cached method, and arbitrary validation 
can be done on the object to decide if caching it or not.

The post condition bean must implement the PostCondition interface which looks 
like this:

public interface PostCondition {
    boolean shouldCache(Object object);
}

The implementation of where the postcondition bean is setted follows the same 
way that is done for the keyGeneratorName attribute (in the 
CacheAttributeSourceImpl class).

I also added an Integration test to test the behaviour

I'm attaching the patch, let me know if you think this is valuable to the 
project, or any doubts you may have.

Regards

Original issue reported on code.google.com by carlo.sc...@gmail.com on 14 Jan 2011 at 10:29

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by eric.dalquist on 14 Jan 2011 at 6:00

GoogleCodeExporter commented 8 years ago
I think this is a good starting point. I'm going to expand on the interceptor a 
bit but it will have the functionality you're defining here as well as some 
additional features.

Original comment by eric.dalquist on 19 Apr 2011 at 10:26

GoogleCodeExporter commented 8 years ago
The code is in place via commit 
http://code.google.com/p/ehcache-spring-annotations/source/detail?r=639

I'm leaving this issue open as the following tasks still need to be completed:
* Create unit test for configuring the default interceptor in the app context
* Create unit test using a custom interceptor impl defined in the @Cacheable 
annotation

Original comment by eric.dalquist on 19 Apr 2011 at 10:31

GoogleCodeExporter commented 8 years ago

Original comment by eric.dalquist on 20 Apr 2011 at 4:08

GoogleCodeExporter commented 8 years ago
Hey.. nice you took a look at this.. I will download the new version and see 
how it works, and remove my patched one from my project.

Thanks, i think it will be a good addition..

Original comment by carlo.sc...@gmail.com on 20 Apr 2011 at 4:11

GoogleCodeExporter commented 8 years ago
Great. I'd like to get your feedback on the new interceptor interfaces:

http://code.google.com/p/ehcache-spring-annotations/source/browse/trunk/src/main
/java/com/googlecode/ehcache/annotations/CacheableInterceptor.java
http://code.google.com/p/ehcache-spring-annotations/source/browse/trunk/src/main
/java/com/googlecode/ehcache/annotations/TriggersRemoveInterceptor.java

Will those fulfill your needs?

-Eric

On Wed, Apr 20, 2011 at 11:12 AM, <ehcache-spring-annotations@googlecode.com

Original comment by eric.dalquist on 20 Apr 2011 at 4:17

GoogleCodeExporter commented 8 years ago
Hi Eric, It looks like it will fullfill my needs, actually it looks like it can 
do a lot more.... which is nice, it has like many "lifecycle hooks" which can 
be take advantage of.

I think, for now, I will use the postInvokeCacheable method and check on the 
"value", ignoring the other parameters.

I'm using your project in Production. Do you think this enhancement, and the 
trunk in general is stable enough to test this new functionality and replace my 
patch??.

If this is the case I'll replace it tomorrow and give you more feedback, in if 
it is actually working.

If not, I will only use it in testing but not add it to the production code 
until the next stable release..

Kind Regards,

Carlo

Original comment by carlo.sc...@gmail.com on 20 Apr 2011 at 4:28

GoogleCodeExporter commented 8 years ago
Trunk should be pretty stable but I haven't done any of the normal profiling
tests I do before cutting a release. I'm going to try and cut a 1.2.0-RC1
this week.

-Eric

On Wed, Apr 20, 2011 at 11:29 AM, <ehcache-spring-annotations@googlecode.com

Original comment by eric.dalquist on 20 Apr 2011 at 4:43