org.jasig.services.persondir.support
Class CachingPersonAttributeDaoImpl

java.lang.Object
  extended by org.jasig.services.persondir.support.BasePersonAttributeDao
      extended by org.jasig.services.persondir.support.AbstractFlatteningPersonAttributeDao
          extended by org.jasig.services.persondir.support.AbstractDefaultAttributePersonAttributeDao
              extended by org.jasig.services.persondir.support.CachingPersonAttributeDaoImpl
All Implemented Interfaces:
IPersonAttributeDao, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean

public class CachingPersonAttributeDaoImpl
extends AbstractDefaultAttributePersonAttributeDao
implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanNameAware

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

Configuration:

Property Description Required Default
cachedPersonAttributesDao The 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

Field Summary
protected static Set<IPersonAttributes> NULL_RESULTS_OBJECT
           
protected  org.apache.commons.logging.Log statsLogger
           
 
Fields inherited from class org.jasig.services.persondir.support.BasePersonAttributeDao
logger
 
Fields inherited from interface org.jasig.services.persondir.IPersonAttributeDao
WILDCARD, WILDCARD_PATTERN
 
Constructor Summary
CachingPersonAttributeDaoImpl()
           
 
Method Summary
 void afterPropertiesSet()
           
 Set<String> getAvailableQueryAttributes()
           
 IPersonAttributeDao getCachedPersonAttributesDao()
           
 Set<String> getCacheKeyAttributes()
          Deprecated. these should be retrieved from the provided CacheKeyGenerator if applicable
 org.springmodules.cache.key.CacheKeyGenerator getCacheKeyGenerator()
           
 long getMisses()
           
 Set<IPersonAttributes> getNullResultsObject()
           
 Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(Map<String,List<Object>> seed)
          Wraps the call to the specified cachedPersonAttributesDao IPersonAttributeDao delegate with a caching layer.
 Set<String> getPossibleUserAttributeNames()
           
 long getQueries()
           
 Map<Serializable,Set<IPersonAttributes>> getUserInfoCache()
           
 boolean isCacheNullResults()
           
 void removeUserAttributes(Map<String,Object> seed)
           
 void removeUserAttributes(String uid)
           
 void removeUserAttributesMultivaluedSeed(Map<String,List<Object>> seed)
           
 void setBeanName(String name)
           
 void setCachedPersonAttributesDao(IPersonAttributeDao cachedPersonAttributesDao)
          The IPersonAttributeDao to cache results from.
 void setCacheKeyAttributes(Set<String> cacheKeyAttributes)
          Deprecated. these should be set on the provided CacheKeyGenerator if applicable
 void setCacheKeyGenerator(org.springmodules.cache.key.CacheKeyGenerator cacheKeyGenerator)
          The CacheKeyGenerator to use for generating cache keys.
 void setCacheNullResults(boolean cacheNullResults)
          If null results should be cached to avoid repeating failed lookups.
 void setNullResultsObject(Set<IPersonAttributes> nullResultsObject)
          Used to specify the placeholder object to put in the cache for null results.
 void setUserInfoCache(Map<Serializable,Set<IPersonAttributes>> userInfoCache)
          The Map to use for caching results.
 
Methods inherited from class org.jasig.services.persondir.support.AbstractDefaultAttributePersonAttributeDao
getPerson, getUsernameAttributeProvider, setUsernameAttributeProvider, toSeedMap
 
Methods inherited from class org.jasig.services.persondir.support.AbstractFlatteningPersonAttributeDao
getPeople, toMultivaluedSeed
 
Methods inherited from class org.jasig.services.persondir.support.BasePersonAttributeDao
flattenResults, getMultivaluedUserAttributes, getMultivaluedUserAttributes, getUserAttributes, getUserAttributes
 
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 Set<IPersonAttributes> NULL_RESULTS_OBJECT

statsLogger

protected org.apache.commons.logging.Log statsLogger
Constructor Detail

CachingPersonAttributeDaoImpl

public CachingPersonAttributeDaoImpl()
Method Detail

getCachedPersonAttributesDao

public IPersonAttributeDao getCachedPersonAttributesDao()
Returns:
Returns the cachedPersonAttributesDao.

setCachedPersonAttributesDao

public void setCachedPersonAttributesDao(IPersonAttributeDao cachedPersonAttributesDao)
The IPersonAttributeDao to cache results from.

Parameters:
cachedPersonAttributesDao - The cachedPersonAttributesDao to set.

getCacheKeyAttributes

@Deprecated
public Set<String> getCacheKeyAttributes()
Deprecated. these should be retrieved from the provided CacheKeyGenerator if applicable

Returns:
Returns the cacheKeyAttributes.

setCacheKeyAttributes

@Deprecated
public void setCacheKeyAttributes(Set<String> cacheKeyAttributes)
Deprecated. these should be set on the provided CacheKeyGenerator if applicable

Parameters:
cacheKeyAttributes - The cacheKeyAttributes to set.

getUserInfoCache

public Map<Serializable,Set<IPersonAttributes>> getUserInfoCache()
Returns:
Returns the userInfoCache.

setUserInfoCache

public void setUserInfoCache(Map<Serializable,Set<IPersonAttributes>> userInfoCache)
The Map to use for caching results. Only get, put and remove are used so the Map may be backed by a real caching implementation.

Parameters:
userInfoCache - The userInfoCache to set.

isCacheNullResults

public boolean isCacheNullResults()
Returns:
the cacheNullResults

setCacheNullResults

public void setCacheNullResults(boolean cacheNullResults)
If null results should be cached to avoid repeating failed lookups. Defaults to false.

Parameters:
cacheNullResults - the cacheNullResults to set

getNullResultsObject

public Set<IPersonAttributes> getNullResultsObject()
Returns:
the nullResultsObject

setNullResultsObject

public void setNullResultsObject(Set<IPersonAttributes> nullResultsObject)
Used to specify the placeholder object to put in the cache for null results. Defaults to a minimal Set. Most installations will not need to set this.

Parameters:
nullResultsObject - the nullResultsObject to set

getCacheKeyGenerator

public org.springmodules.cache.key.CacheKeyGenerator getCacheKeyGenerator()
Returns:
the cacheKeyGenerator

setCacheKeyGenerator

public void setCacheKeyGenerator(org.springmodules.cache.key.CacheKeyGenerator cacheKeyGenerator)
The CacheKeyGenerator to use for generating cache keys.

Parameters:
cacheKeyGenerator - the cacheKeyGenerator to set

setBeanName

public void setBeanName(String name)
Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

getMisses

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

getQueries

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

getPeopleWithMultivaluedAttributes

public Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(Map<String,List<Object>> seed)
Wraps the call to the specified cachedPersonAttributesDao IPersonAttributeDao delegate with a caching layer. Results are cached using keys generated by #getCacheKey(Map).

Specified by:
getPeopleWithMultivaluedAttributes in interface IPersonAttributeDao
See Also:
IPersonAttributeDao.getPeopleWithMultivaluedAttributes(java.util.Map)

removeUserAttributes

public void removeUserAttributes(String uid)

removeUserAttributes

public void removeUserAttributes(Map<String,Object> seed)

removeUserAttributesMultivaluedSeed

public void removeUserAttributesMultivaluedSeed(Map<String,List<Object>> seed)

getPossibleUserAttributeNames

public Set<String> getPossibleUserAttributeNames()
Specified by:
getPossibleUserAttributeNames in interface IPersonAttributeDao

getAvailableQueryAttributes

public Set<String> getAvailableQueryAttributes()
Specified by:
getAvailableQueryAttributes in interface IPersonAttributeDao


Copyright © 2012 Jasig. All Rights Reserved.