public class ObjectCache<K,V>
extends java.lang.Object
system properties.
Use the ObjectCache(String) constructor to
create a named instance. The cache type can then be configured with a
property named
tvc.core.util.cache.NAME, where name is the name of the cache.
Alternatively it's possible to define the default cache type using the
tvc.core.util.cache property. The accepted values for these
properties are NONE, SOFT, and STRONG.
The default type will be STRONG unless the default type has been
configured to something else.
Here is a short description on the available types:
NONE - Objects will not be cached.SOFT - Objects will be cached using soft references.
STRONG - Objects will be cached using strong (actual)
references.
| Modifier and Type | Field and Description |
|---|---|
static int |
NONE
No objects will be cached when using this type.
|
static int |
SOFT
Objects will be cached using soft references.
|
static int |
STRONG
Objects will be cached using strong references.
|
| Constructor and Description |
|---|
ObjectCache()
No argument constructor.
|
ObjectCache(int type)
Creates a cache of the specified type.
|
ObjectCache(int type,
ObjectCacheListener listener)
Creates a cache of the specified type.
|
ObjectCache(ObjectCacheListener listener) |
ObjectCache(java.lang.String name)
Creates a cache with the specified name.
|
ObjectCache(java.lang.String name,
int def)
Creates a cache with the specified name.
|
ObjectCache(java.lang.String name,
int def,
ObjectCacheListener listener)
Creates a cache with the specified name.
|
ObjectCache(java.lang.String name,
ObjectCacheListener listener)
Creates a cache with the specified name.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(ObjectCacheListener listener) |
void |
clear()
Clears the cache.
|
static boolean |
clear(java.lang.String name)
Clears a cache.
|
static void |
clearAll()
Clear all cache instances.
|
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
boolean |
equal(java.lang.Object o)
Compares the objects and returns true if they are equal.
|
V |
get(java.lang.Object key)
Returns the object cached using the specified key.
|
static java.util.Iterator<ObjectCache<?,?>> |
getAll()
Returns an iterator containing all ObjectCache instances
|
static ObjectCache<?,?> |
getById(int id) |
int |
getId() |
java.util.Set<K> |
getKeys() |
java.lang.String |
getName()
Returns the name of the cache, if one was specified in the
constructor. |
int |
getType()
Returns the type.
|
int |
hashCode()
Returns the objects hash code.
|
boolean |
isEmpty() |
boolean |
isNone()
Returns
true if the type is equal to NONE. |
boolean |
isSoft()
Returns
true if the type is equal to SOFT. |
boolean |
isStrong()
Returns
true if the type is equal to STRONG. |
java.util.Map<K,V> |
map()
Returns the internal
Map. |
protected java.lang.String |
paramString()
Returns a parameterized string containing debug information about the
object current state.
|
V |
remove(java.lang.Object key)
Removes an item from the cache.
|
void |
set(K key,
V value)
Sets the value in the cache associated with the specified key.
|
int |
size()
Returns the number of objects in the cache.
|
java.lang.String |
toString()
Returns a string representation of the object containing debug
information about it's current state.
|
public static final int NONE
getType(),
isNone(),
Constant Field Valuespublic static final int SOFT
getType(),
isSoft(),
Constant Field Valuespublic static final int STRONG
getType(),
isStrong(),
Constant Field Valuespublic ObjectCache()
public ObjectCache(ObjectCacheListener listener)
listener - A custom listnerpublic ObjectCache(java.lang.String name)
public ObjectCache(java.lang.String name,
ObjectCacheListener listener)
public ObjectCache(int type)
public ObjectCache(int type,
ObjectCacheListener listener)
public ObjectCache(java.lang.String name,
int def)
name - The name of the cache.def - The default type.public ObjectCache(java.lang.String name,
int def,
ObjectCacheListener listener)
name - The name of the cache.def - The default type.listener - The listener.public void addListener(ObjectCacheListener listener)
public int getId()
public int getType()
public boolean isNone()
true if the type is equal to NONE.public boolean isSoft()
true if the type is equal to SOFT.public boolean isStrong()
true if the type is equal to STRONG.public java.lang.String getName()
constructor.public V get(java.lang.Object key)
public V remove(java.lang.Object key)
key - The key of the item to remove from the cache.public boolean containsKey(java.lang.Object key)
key - The keypublic java.util.Set<K> getKeys()
public boolean containsValue(java.lang.Object value)
value - The value to checkpublic boolean isEmpty()
public int size()
public void clear()
public static ObjectCache<?,?> getById(int id)
public static java.util.Iterator<ObjectCache<?,?>> getAll()
public static void clearAll()
public static boolean clear(java.lang.String name)
name - The name of the cache to clearpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equal(java.lang.Object o)
protected java.lang.String paramString()
public java.lang.String toString()
toString in class java.lang.ObjectCopyright ? Technia AB. All Rights Reserved.