org.omnifaces.component.output.cache
Class TimeToLiveCache

java.lang.Object
  extended by org.omnifaces.component.output.cache.TimeToLiveCache
All Implemented Interfaces:
java.io.Serializable, Cache
Direct Known Subclasses:
DefaultCache

public abstract class TimeToLiveCache
extends java.lang.Object
implements Cache

Base class that can be used by Map based caches that don't support time to live semantics and arbitrary attributes natively.

Since:
1.1
Author:
Arjan Tijms
See Also:
Serialized Form

Constructor Summary
TimeToLiveCache(java.lang.Integer defaultTimeToLive)
           
 
Method Summary
 java.lang.String get(java.lang.String key)
          Gets a value from the cache
 java.lang.Object getAttribute(java.lang.String key, java.lang.String name)
          Gets a named attribute from the cache entry identified by the key parameter.
 void put(java.lang.String key, java.lang.String value)
          Stores a value in the cache
 void put(java.lang.String key, java.lang.String value, int timeToLive)
          Stores a value in the cache
 void putAttribute(java.lang.String key, java.lang.String name, java.lang.Object value, int timeToLive)
          Stores a named attribute in the cache entry identified by the key parameter.
 void remove(java.lang.String key)
          Removes a value from the cache
protected  void setCacheStore(java.util.Map<java.lang.String,CacheEntry> cacheStore)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeToLiveCache

public TimeToLiveCache(java.lang.Integer defaultTimeToLive)
Method Detail

get

public java.lang.String get(java.lang.String key)
Description copied from interface: Cache
Gets a value from the cache

Specified by:
get in interface Cache
Parameters:
key - the key under which a value was previously stored
Returns:
The previously stored value, or null if no such value exists

put

public void put(java.lang.String key,
                java.lang.String value)
Description copied from interface: Cache
Stores a value in the cache

Specified by:
put in interface Cache
Parameters:
key - the key under which a value is to be stored
value - the value that is to be stored

put

public void put(java.lang.String key,
                java.lang.String value,
                int timeToLive)
Description copied from interface: Cache
Stores a value in the cache

Specified by:
put in interface Cache
Parameters:
key - the key under which a value is to be stored
value - the value that is to be stored
timeToLive - the amount of time in seconds for which the cached value is valid from the time it's being added to the cache. It's provider specific whether the cache implementation will actually remove (evict) the entry after this time has elapsed or will only perform a check upon accessing the cache entry. Whatever method the implementation chooses; after this time is elapsed a call to Cache.get(String) should return null.

putAttribute

public void putAttribute(java.lang.String key,
                         java.lang.String name,
                         java.lang.Object value,
                         int timeToLive)
Description copied from interface: Cache
Stores a named attribute in the cache entry identified by the key parameter.

Specified by:
putAttribute in interface Cache
Parameters:
key - key that identifies the first level cache entry
name - name of the attribute in the second level
value - value associated with the {key, name} hierarchy.
timeToLive - the amount of time in seconds for which the cached value is valid. Only used when there's no first level entry yet. See Cache.putAttribute(String, String, Object, int)

getAttribute

public java.lang.Object getAttribute(java.lang.String key,
                                     java.lang.String name)
Description copied from interface: Cache
Gets a named attribute from the cache entry identified by the key parameter.

This in effect implements a 2-level multi-map, which the single main value stored in the first level, and the optional attributes stored in the second level.

Specified by:
getAttribute in interface Cache
Parameters:
key - key that identifies the first level cache entry
name - name of the attribute in the second level
Returns:
the value associated with the {key, name} hierarchy.

remove

public void remove(java.lang.String key)
Description copied from interface: Cache
Removes a value from the cache

Specified by:
remove in interface Cache
Parameters:
key - the key under which a value is to be stored

setCacheStore

protected void setCacheStore(java.util.Map<java.lang.String,CacheEntry> cacheStore)