org.kuali.rice.kew.util
Class CachingInterceptor

java.lang.Object
  extended by org.kuali.rice.kew.util.CachingInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class CachingInterceptor
extends Object
implements org.aopalliance.intercept.MethodInterceptor

This is a generic caching proxy for KEW, using the cache administrator service to store results. It's inteded for caching query results for a DAO, but it likely has broader use.

It will cache the results of calls matching method names which are set in setCacheForMethods(java.lang.String[]). It will clear this "cache group" for calls with matching method names set in setClearCacheOnMethods(java.lang.String[]).

The cache group name (see setCacheGroupName(String)) in most instances should unique for each class that is proxied.

Configuration should be done through Spring, probably using BeanNameAutoProxyCreator.

NOTE: One important assumption here is that the arguments for the methods being cached will all have Object.toString() implementations such that o1.equals(o2) iff o1.toString().equals(o2.toString()).

Author:
Kuali Rice Team (rice.collab@kuali.org)

Field Summary
private  Set<String> cacheForMethods
           
private  String cacheGroupName
           
private  Set<String> clearCacheOnMethods
           
private static org.apache.commons.logging.Log LOG
           
private static Object NULL_OBJECT
           
 
Constructor Summary
CachingInterceptor()
           
 
Method Summary
private  String getCacheKey(String methodName, Object[] args)
          build a cache key based on the method name and the parameters
 Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
          This overridden method intercepts calls, and if the intercepted method is in clearCacheOnMethods the cache is purged, then the method is called and any results returned. if the intercepted method is in cacheForMethods the cache is checked.
 void setCacheForMethods(String[] methods)
           
 void setCacheGroupName(String name)
           
 void setClearCacheOnMethods(String[] methods)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static org.apache.commons.logging.Log LOG

clearCacheOnMethods

private Set<String> clearCacheOnMethods

cacheForMethods

private Set<String> cacheForMethods

cacheGroupName

private String cacheGroupName

NULL_OBJECT

private static final Object NULL_OBJECT
Constructor Detail

CachingInterceptor

public CachingInterceptor()
Method Detail

setClearCacheOnMethods

public void setClearCacheOnMethods(String[] methods)

setCacheForMethods

public void setCacheForMethods(String[] methods)

setCacheGroupName

public void setCacheGroupName(String name)

invoke

public Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
              throws Throwable
This overridden method intercepts calls, and

Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
Throwable
See Also:
MethodInterceptor.invoke(org.aopalliance.intercept.MethodInvocation)

getCacheKey

private String getCacheKey(String methodName,
                           Object[] args)
build a cache key based on the method name and the parameters

Parameters:
methodName -
args -
Returns:


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.