com.googlecode.ehcache.annotations
Interface CacheableInterceptor

All Known Implementing Classes:
DefaultCacheableInterceptor

public interface CacheableInterceptor

Used by Cacheable to allow logic to be injected into the caching API. Normal execution workflow looks like:

  1. Generate cache key
  2. Cache lookup
  3. If Cache lookup finds an entry for the key, preInvokeCachable(Ehcache, MethodInvocation, Serializable, Object) is called
  4. Proceed with method invocation and capture the returned value
  5. Call postInvokeCacheable(Ehcache, MethodInvocation, Serializable, Object)
  6. If postInvokeCacheable returns true the value is cached
  7. Return the value
Exception execution workflow looks like (as long as Cacheable.exceptionCacheName() is defined):
  1. Generate cache key
  2. Exception cache lookup
  3. If lookup finds an exception preInvokeCacheableException(Ehcache, MethodInvocation, Serializable, Throwable) is called
  4. Cache lookup
  5. If lookup finds an entry preInvokeCachable(Ehcache, MethodInvocation, Serializable, Object) is called
  6. Proceed with method invocation and capture the returned value
  7. If an exception is thrown by the method invocation:
    1. Call postInvokeCacheableException(Ehcache, MethodInvocation, Serializable, Throwable)
    2. If postInvokeCacheableException returns true the exception is cached
    3. Throw the exception
  8. Else:
    1. Call postInvokeCacheable(Ehcache, MethodInvocation, Serializable, Object)
    2. If postInvokeCacheable returns true the value is cached
    3. Return the value

Version:
$Revision: 656 $
Author:
Eric Dalquist

Method Summary
 boolean postInvokeCacheable(net.sf.ehcache.Ehcache cache, org.aopalliance.intercept.MethodInvocation methodInvocation, java.io.Serializable key, java.lang.Object value)
          Called after a method invocation but before the returned value is cached Not used when Cacheable.selfPopulating() is set to true.
 boolean postInvokeCacheableException(net.sf.ehcache.Ehcache exceptionCache, org.aopalliance.intercept.MethodInvocation methodInvocation, java.io.Serializable key, java.lang.Throwable t)
          Called after a method invocation throws an exception AND an exception cache is configured for the interceptor but before the exception is cached
 boolean preInvokeCachable(net.sf.ehcache.Ehcache cache, org.aopalliance.intercept.MethodInvocation methodInvocation, java.io.Serializable key, java.lang.Object value)
          Called after a cache hit but before the method invocation.
 boolean preInvokeCacheableException(net.sf.ehcache.Ehcache exceptionCache, org.aopalliance.intercept.MethodInvocation methodInvocation, java.io.Serializable key, java.lang.Throwable t)
          Called after the cache lookup but before the method invocation if a cached exception was found
 

Method Detail

preInvokeCachable

boolean preInvokeCachable(net.sf.ehcache.Ehcache cache,
                          org.aopalliance.intercept.MethodInvocation methodInvocation,
                          java.io.Serializable key,
                          java.lang.Object value)
Called after a cache hit but before the method invocation. Not used when Cacheable.selfPopulating() is set to true.

Parameters:
cache - The cache used for this invocation
methodInvocation - The method invocation that has been intercepted
key - The generated cache key
value - The found cache value if any, may be null
Returns:
true if the intercepted method invocation should be invoked, false if it should not be invoked and the value should be returned.

postInvokeCacheable

boolean postInvokeCacheable(net.sf.ehcache.Ehcache cache,
                            org.aopalliance.intercept.MethodInvocation methodInvocation,
                            java.io.Serializable key,
                            java.lang.Object value)
Called after a method invocation but before the returned value is cached Not used when Cacheable.selfPopulating() is set to true.

Parameters:
cache - The cache used for this invocation
methodInvocation - The method invocation that has been intercepted
key - The generated cache key
value - The value returned by the invocation
Returns:
true if the value should be cached, false if not

preInvokeCacheableException

boolean preInvokeCacheableException(net.sf.ehcache.Ehcache exceptionCache,
                                    org.aopalliance.intercept.MethodInvocation methodInvocation,
                                    java.io.Serializable key,
                                    java.lang.Throwable t)
Called after the cache lookup but before the method invocation if a cached exception was found

Parameters:
exceptionCache - The cache used for this invocation
methodInvocation - The method invocation that has been intercepted
key - The generated cache key
t - The exception thrown by the invocation
Returns:
true if the intercepted method invocation should be invoked, false if it should not be invoked and the cached exception thrown.

postInvokeCacheableException

boolean postInvokeCacheableException(net.sf.ehcache.Ehcache exceptionCache,
                                     org.aopalliance.intercept.MethodInvocation methodInvocation,
                                     java.io.Serializable key,
                                     java.lang.Throwable t)
Called after a method invocation throws an exception AND an exception cache is configured for the interceptor but before the exception is cached

Parameters:
exceptionCache - The cache used for this invocation
methodInvocation - The method invocation that has been intercepted
key - The generated cache key
t - The exception thrown by the invocation
Returns:
true if the exception should be cached, false if not


Copyright © 2011. All Rights Reserved.