jsr107/jsr107spec — Issue #46: Add onException() attribute to caching annotations.
Author: chrisdennis
Created: 2011-11-28 22:13:57+00:00
State: open

CachePut, CacheRemoveAll and CacheRemoveEntry all have an afterInvocation() boolean attribute which is doc'ed to behave as follows:

```java
/**
* (Optional) When {@link javax.cache.Cache#put(Object, Object)} should be
* called. If true it is called after the annotated method invocation completes
* successfully. If false it is called before the annotated method is invoked.
*

* Defaults to true.
*

* If true and the annotated method throws an exception the put will not be executed.
*/
@Nonbinding
boolean afterInvocation() default true;
```
This attribute seems to be driving two different forms of behavior:

1. Whether the operation happens before or after the method body is executed.
2. Whether the operation happens when the method returns abnormally.

It seem thats these two decisions should be independent, i.e. there may be some circumstances where I want the operation to occur in a finally block. That would suggest we should have two attributes:

```java
boolean afterInvocation() default true;
boolean onException() default false;
```