Support 'unless' expression for cache veto

Allow @Cachable, @CachePut and equivalent XML configuration to provide
a SpEL expression that can be used to veto putting an item into the
cache. Unlike 'condition' the 'unless' parameter is evaluated after
the method has been called and can therefore reference the #result.

For example:

    @Cacheable(value="book",
        condition="#name.length < 32",
        unless="#result.hardback")

This commit also allows #result to be referenced from @CacheEvict
expressions as long as 'beforeInvocation' is false.

Issue: SPR-8871
This commit is contained in:
Phillip Webb
2013-01-24 17:16:29 -08:00
parent 3252cb5a0f
commit 8c2ace33cb
22 changed files with 385 additions and 106 deletions

View File

@@ -11,6 +11,7 @@ Changes in version 3.2.2 (2013-03-07)
* DefaultMessageListenerContainer logs recovery failures at error level and exposes "isRecovering()" method (SPR-10230)
* MediaType throws dedicated InvalidMediaTypeException instead of generic IllegalArgumentException (SPR-10226)
* consistent use of LinkedHashMaps and independent getAttributeNames Enumeration in Servlet/Portlet mocks (SPR-10224)
* support 'unless' expression for cache veto (SPR-8871)
Changes in version 3.2.1 (2013-01-24)