org.wanghy.cache.interceptor.caching
Class CachingInterceptor

java.lang.Object
  extended byorg.wanghy.cache.interceptor.caching.CachingAspectSupport
      extended byorg.wanghy.cache.interceptor.caching.CachingInterceptor
All Implemented Interfaces:
Advice, InitializingBean, Interceptor, MethodInterceptor

public class CachingInterceptor
extends CachingAspectSupport
implements MethodInterceptor, InitializingBean

Caches the return value of the intercepted method.

Version:
$Revision: 1.9 $ $Date: 2005/03/03 02:02:30 $
Author:
Alex Ruiz

Field Summary
private  CacheProviderFacade cacheProviderFacade
          Cache provider facade.
private static Log logger
          Message logger.
 
Fields inherited from class org.wanghy.cache.interceptor.caching.CachingAspectSupport
NULL_ENTRY
 
Constructor Summary
CachingInterceptor()
          Constructor.
 
Method Summary
 void afterPropertiesSet()
          Event raised by the Spring container indicating that all the properties of this class has been set.
protected  Cached getCachingAttribute(MethodInvocation methodInvocation)
          Returns the metadata attribute of the intercepted method.
 Object invoke(MethodInvocation methodInvocation)
          Returns from the cache provider the value saved with the key generated using the specified MethodInvocation.
 void setCacheProviderFacade(CacheProviderFacade cacheProviderFacade)
          Setter for the field cacheProviderFacade.
 void setCachingAttributes(Properties cachingAttributes)
          Set properties with method names as keys and caching-attribute descriptors (parsed via CachingAttributeEditor) as values.
 
Methods inherited from class org.wanghy.cache.interceptor.caching.CachingAspectSupport
getCacheKeyGenerator, getCachingAttributeSource, getEntryStoredListener, setCacheKeyGenerator, setCachingAttributeSource, setEntryStoredListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static Log logger
Message logger.


cacheProviderFacade

private CacheProviderFacade cacheProviderFacade
Cache provider facade.

Constructor Detail

CachingInterceptor

public CachingInterceptor()
Constructor.

Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Event raised by the Spring container indicating that all the properties of this class has been set. If the key generator is null, this method will create a new instance of HashCodeCacheKeyGenerator.

Specified by:
afterPropertiesSet in interface InitializingBean

getCachingAttribute

protected final Cached getCachingAttribute(MethodInvocation methodInvocation)
Returns the metadata attribute of the intercepted method.

Parameters:
methodInvocation - the description of an invocation to the method.
Returns:
the metadata attribute of the intercepted method.

invoke

public final Object invoke(MethodInvocation methodInvocation)
                    throws Throwable
Returns from the cache provider the value saved with the key generated using the specified MethodInvocation. If the object is not found in the cache, the intercepted method is executed and its returned value is saved in the cached and returned by this method.

Specified by:
invoke in interface MethodInterceptor
Parameters:
methodInvocation - the description of the intercepted method.
Returns:
the object stored in the cache.
Throws:
Throwable

setCacheProviderFacade

public final void setCacheProviderFacade(CacheProviderFacade cacheProviderFacade)
Setter for the field cacheProviderFacade.

Parameters:
cacheProviderFacade - the new value to set

setCachingAttributes

public final void setCachingAttributes(Properties cachingAttributes)
Set properties with method names as keys and caching-attribute descriptors (parsed via CachingAttributeEditor) as values.

Note: Method names are always applied to the target class, no matter if defined in an interface or the class itself.

Internally, a NameMatchCachingAttributeSource will be created from the given properties.

See Also:
NameMatchCachingAttributeSource


Copyright © 2004-2005 Alex Ruiz. All Rights Reserved.