Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support 'unless' expression for cache veto #220

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Owner

philwebb commented Jan 25, 2013

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:

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

@ghost ghost assigned jhoeller Jan 25, 2013

Hi Philwebb,

I am using the new feature "unless", but it is not working. I am using ehcache as the cache container.

Here is the thread I opened in stackoverflow:
http://stackoverflow.com/questions/17440526/using-element-unless-for-cacheable-spring-3-2-3-not-working

If you could know a little about what is going on, I am really glad to know and appreciate your help.
Thanks!

Owner

philwebb commented Jul 5, 2013

Could you please raise a JIRA for this. Ideally with an issue to reproduce the problem.

I have pasted all the necessary codes related with caching to JIRA. Hope that helps.

JIRA link: https://jira.springsource.org/browse/SPR-10724
Thanks!

@philwebb philwebb closed this Aug 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment