|
uPortal 2.4.1 API Documentation |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
java.util.HashMap
org.jasig.portal.utils.SmartCache
The SmartCache class is used to store objects in memory for a specified amount of time. The time should be specified in seconds. If the time is specified as a negative value, it will be cahced indefinitely.
Constructor Summary | |
SmartCache()
Instantiate SmartCache with a default expiration timeout of one hour. |
|
SmartCache(int iExpirationTimeout)
Instantiate a new SmartCache. |
Method Summary | |
java.lang.Object |
get(java.lang.Object key)
Get an object from the cache. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Add a new value to the cache. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value,
long lCacheInterval)
Add a new value to the cache |
Methods inherited from class java.util.HashMap |
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Constructor Detail |
public SmartCache(int iExpirationTimeout)
import org.jasig.portal.utils.SmartCache;
public class CacheClient {
private static SmartCache cache = new SmartCache(3600); // This cache's values will expire in one hour
public static void main (String[] args) {
// Try to get a value from the cache
String aKey = "exampleKey";
String aValue = (String)cache.get(aKey);
if (aValue == null) {
// If we are here, the value has either expired or not in the cache
// so we will get the value and stuff it in the cache
String freshValue = someMethodWhichReturnsAString();
// Make sure it isn't null before putting it into the cache
if (freshValue != null) {
cache.put(aKey, freshValue);
aValue = freshValue;
}
}
System.out.println ("Got the value: " + aValue);
}
}
iExpirationTimeout
- specified in secondspublic SmartCache()
Method Detail |
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
key
- the key, typically a Stringvalue
- the value
public java.lang.Object put(java.lang.Object key, java.lang.Object value, long lCacheInterval)
key
- the key, typically a Stringvalue
- the valuelCacheInterval
- an expiration timeout value, in seconds, which will
override the default cache value just for this item. If a negative timeout
value is specified, the value will be cached indefinitely.
public java.lang.Object get(java.lang.Object key)
key
- the key, typically a String
|
uPortal 2.4.1 API Documentation |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |