org.kuali.rice.core.api.cache
Class CacheKeyUtils

java.lang.Object
  extended by org.kuali.rice.core.api.cache.CacheKeyUtils

public final class CacheKeyUtils
extends Object

A utility class that can be used to generate cache keys for more complex method signatures. Currently, the utilities on this class focus on generating cache keys for collections of objects. Since the caching infrastructure only supports a single @{code String} value as a key for cache entries, this utility helps to provide a standard way to generate such compound caching keys.

It is possible to use this utility class when specifying keys for cached objects using Spring's caching abstraction (which is what the Rice caching infrastructure is built on). This is possible using the Spring Expression Language (SPEL). An example might look something like the following:

 @Cacheable(value = "StuffCache", key="'ids=' + T(org.kuali.rice.core.api.cache.CacheKeyUtils).key(#p0)")
 List<Stuff> getStuff(List<String> stuffIds); 
 

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

Method Summary
static
<K extends Comparable<K>>
String
key(Collection<K> col)
          Create a String key value out of a Collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

key

public static <K extends Comparable<K>> String key(Collection<K> col)
Create a String key value out of a Collection. It accomplishes this by first sorting the given collection (entries in the collection must implement Comparable) and then construct a key based on the .toString() values of each item in the sorted collection.

The sorting of the given list happens on a copy of the list, so this method does not side-affect the given list.

Type Parameters:
K - the col type
Parameters:
col - the collection. if null will return "", if empty, will return "[]"
Returns:
the collection as a string value


Copyright © 2005-2012 The Kuali Foundation. All Rights Reserved.