public class BasicSessionCache extends java.lang.Object implements SessionCache
Eviction of BasicSessionCache entries is accomplished by controlling the maximum number of entries in the cache. This
maximum value is set by calling setCapacity(int)
. The eldest entry in the cache (the first entry added) is
always evicted before any others.
BasicSessionClass is a thread safe class. Access to the cache data structures is synchronized at the method level. Care must be taken by subclasses to ensure that method level synchronization is maintained.
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_CAPACITY |
protected BoundedHashMap<java.lang.Object,java.lang.Object> |
entries |
Constructor and Description |
---|
BasicSessionCache()
Creates a BasicSessionCache with the default capacity.
|
BasicSessionCache(int capacity)
Creates a BasicSessionCache with a specified maximum number of entries.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all entries from the cache.
|
boolean |
contains(java.lang.Object key)
Returns true if the cache contains a specified key, and false if it does not.
|
java.lang.Object |
get(java.lang.Object key)
Returns a reference to an entry's value in the cache corresponding to a specified key, or null if no entry with
that key exists.
|
int |
getCapacity()
Returns the maximum number of entries in the cache.
|
int |
getEntryCount()
Returns the number of entries currently in the cache.
|
java.util.Set<java.lang.Object> |
getKeySet()
Returns a
Set view of the keys contained in the cache. |
void |
put(java.lang.Object key,
java.lang.Object value)
Adds an entry in the cache with a specified key and value.
|
java.lang.Object |
remove(java.lang.Object key)
Removes the entry with the specified key from the cache, and returns that entry's value.
|
void |
setCapacity(int capacity)
Sets the maximum number of entries in the cache.
|
protected static final int DEFAULT_CAPACITY
protected BoundedHashMap<java.lang.Object,java.lang.Object> entries
public BasicSessionCache()
public BasicSessionCache(int capacity)
capacity
- maximum number of entries in the cache.java.lang.IllegalArgumentException
- if capacity is negative.public void clear()
clear
in interface SessionCache
public boolean contains(java.lang.Object key)
contains
in interface SessionCache
key
- the entry key in question. A null value is not permitted.java.lang.IllegalArgumentException
- if the key is null.public java.lang.Object get(java.lang.Object key)
get
in interface SessionCache
key
- the entry key to look for.java.lang.IllegalArgumentException
- if the key is null.public int getCapacity()
getCapacity
in interface SessionCache
public int getEntryCount()
getEntryCount
in interface SessionCache
public java.util.Set<java.lang.Object> getKeySet()
Set
view of the keys contained in the cache. The returned set is immutable: changes
to the set are not reflected in the session cache.getKeySet
in interface SessionCache
Set
view of the keys contained in the cache.public void put(java.lang.Object key, java.lang.Object value)
put
in interface SessionCache
key
- the entry's key. A null value is not permitted.value
- the entry's value. A null value is permitted.java.lang.IllegalArgumentException
- if the key is null.public java.lang.Object remove(java.lang.Object key)
remove
in interface SessionCache
key
- the entry key to look for.public void setCapacity(int capacity)
setCapacity
in interface SessionCache
capacity
- maximum number of entries in the cache.java.lang.IllegalArgumentException
- if capacity is negative.