org.jasig.services.persondir.support
Class CachingPersonAttributeDaoImpl

java.lang.Object
  extended by org.jasig.services.persondir.support.AbstractDefaultAttributePersonAttributeDao
      extended by org.jasig.services.persondir.support.CachingPersonAttributeDaoImpl
All Implemented Interfaces:
IPersonAttributeDao

public class CachingPersonAttributeDaoImpl
extends AbstractDefaultAttributePersonAttributeDao

A configurable caching implementation of IPersonAttributeDao which caches results from a wrapped IPersonAttributeDao.

Configuration:

Property Description Required Default
cachedPersonAttributesDao The org.jasig.portal.services.persondir.IPersonAttributeDao to delegate queries to on cache misses. Yes null
userInfoCache The Map to use for result caching. This class does no cache maintenence. It is assumed the underlying Map implementation will ensure the cache is in a good state at all times. Yes null
cacheKeyAttributes A Set of attribute names to use when building the cache key. The default implementation generates the key as a Map of attributeNames to values retrieved from the seed for the query. Zero length sets are treaded as null. No null
cacheNullResults If the wrapped IPersonAttributeDao returns null for the query should that null value be stored in the cache. No false
nullResultsObject If cacheNullResults is set to true this value is stored in the cache for any query that returns null. This is used as a flag so the same query will return null from the cache by seeing this value No NULL_RESULTS_OBJECT

Version:
$Id
Author:
dgrimwood@unicon.net, Eric Dalquist edalquist@unicon.net

Field Summary
protected static Map NULL_RESULTS_OBJECT
           
protected  Log statsLogger
           
 
Fields inherited from class org.jasig.services.persondir.support.AbstractDefaultAttributePersonAttributeDao
logger
 
Constructor Summary
CachingPersonAttributeDaoImpl()
           
 
Method Summary
 IPersonAttributeDao getCachedPersonAttributesDao()
           
protected  Serializable getCacheKey(Map querySeed)
          Generates a Serializable cache key from the seed parameters according to the documentation of this class.
 Set getCacheKeyAttributes()
           
 long getMisses()
           
 Map getNullResultsObject()
           
 Set getPossibleUserAttributeNames()
          Gets a Set of attribute names that may be returned by the IPersonAttributeDao.getUserAttributes(Map).
 long getQueries()
           
 Map getUserAttributes(Map seed)
          Wraps the call to the specified cachedPersonAttributesDao IPersonAttributeDao delegate with a caching layer.
 Map getUserInfoCache()
           
 boolean isCacheNullResults()
           
 void setCachedPersonAttributesDao(IPersonAttributeDao cachedPersonAttributesDao)
           
 void setCacheKeyAttributes(Set cacheKeyAttributes)
           
 void setCacheNullResults(boolean cacheNullResults)
           
 void setNullResultsObject(Map nullResultsObject)
           
 void setUserInfoCache(Map userInfoCache)
           
 
Methods inherited from class org.jasig.services.persondir.support.AbstractDefaultAttributePersonAttributeDao
getDefaultAttributeName, getUserAttributes, setDefaultAttributeName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_RESULTS_OBJECT

protected static final Map NULL_RESULTS_OBJECT

statsLogger

protected Log statsLogger
Constructor Detail

CachingPersonAttributeDaoImpl

public CachingPersonAttributeDaoImpl()
Method Detail

getCachedPersonAttributesDao

public IPersonAttributeDao getCachedPersonAttributesDao()
Returns:
Returns the cachedPersonAttributesDao.

setCachedPersonAttributesDao

public void setCachedPersonAttributesDao(IPersonAttributeDao cachedPersonAttributesDao)
Parameters:
cachedPersonAttributesDao - The cachedPersonAttributesDao to set.

getCacheKeyAttributes

public Set getCacheKeyAttributes()
Returns:
Returns the cacheKeyAttributes.

setCacheKeyAttributes

public void setCacheKeyAttributes(Set cacheKeyAttributes)
Parameters:
cacheKeyAttributes - The cacheKeyAttributes to set.

getUserInfoCache

public Map getUserInfoCache()
Returns:
Returns the userInfoCache.

setUserInfoCache

public void setUserInfoCache(Map userInfoCache)
Parameters:
userInfoCache - The userInfoCache to set.

isCacheNullResults

public boolean isCacheNullResults()
Returns:
the cacheNullResults

setCacheNullResults

public void setCacheNullResults(boolean cacheNullResults)
Parameters:
cacheNullResults - the cacheNullResults to set

getNullResultsObject

public Map getNullResultsObject()
Returns:
the nullResultsObject

setNullResultsObject

public void setNullResultsObject(Map nullResultsObject)
Parameters:
nullResultsObject - the nullResultsObject to set

getMisses

public long getMisses()
Returns:
Returns the number of cache misses.

getQueries

public long getQueries()
Returns:
Returns the number of queries.

getUserAttributes

public Map getUserAttributes(Map seed)
Wraps the call to the specified cachedPersonAttributesDao IPersonAttributeDao delegate with a caching layer. Results are cached using keys generated by getCacheKey(Map).

Parameters:
seed - immutable Map of attributes to values to seed the query
Returns:
Map from attribute names to values
See Also:
org.jasig.portal.services.persondir.IPersonAttributeDao#getUserAttributes(java.util.Map)

getPossibleUserAttributeNames

public Set getPossibleUserAttributeNames()
Description copied from interface: IPersonAttributeDao
Gets a Set of attribute names that may be returned by the IPersonAttributeDao.getUserAttributes(Map). The names returned represent all possible names IPersonAttributeDao.getUserAttributes(Map) could return. If the dao doesn't have a way to know all possible attribute names this method should return null.
Returns an immutable Set.

Returns:
A {link Set} of possible attribute names for user queries.
See Also:
org.jasig.portal.services.persondir.IPersonAttributeDao#getPossibleUserAttributeNames()

getCacheKey

protected Serializable getCacheKey(Map querySeed)
Generates a Serializable cache key from the seed parameters according to the documentation of this class. If the return value is NULL caching will be disabled for this query.

Parameters:
querySeed - The query to base the key on.
Returns:
A Serializable cache key.


Copyright © 1998-2007 Java Architectures Special Interest Group. All Rights Reserved.