net.obsearch.cache
Class OBCacheByteArray<O>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,O>
net.obsearch.cache.AbstractOBCache<ByteArrayKey,O>
net.obsearch.cache.OBCacheByteArray<O>
- Type Parameters:
O
- The type of object that will be stored in the Cache.
- All Implemented Interfaces:
- Serializable, Cloneable, Map<ByteArrayKey,O>
public final class OBCacheByteArray<O>
- extends AbstractOBCache<ByteArrayKey,O>
By using soft references, an OB cache is implemented The garbage collector
decides based on the access patterns of each reference, which elements are
released and which are kept. The cache controls the loading of items. For
this purpose an OBCacheLoader is provided to control the loading and
instantiation of the objects from secondary storage. That is why this cache
does not have a put method. It assumes that all the requested items exist
in secondary storage otherwise it returns an error. Loading operations
generate a lock but reading operations do not generate any locks.
- Since:
- 0.7
- Author:
- Arnoldo Jose Muller Molina
- See Also:
- Serialized Form
Method Summary |
void |
clearAll()
Makes sure the cache is cleaned and each
object is stored. |
boolean |
exists(byte[] id)
|
O |
get(byte[] id)
Gets the given object, returns null if the object is not found. |
void |
put(byte[] id,
O object)
|
void |
remove(byte[] key)
Remove the given key from the table. |
protected boolean |
removeEldestEntry(Map.Entry<ByteArrayKey,O> eldest)
|
Methods inherited from interface java.util.Map |
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
OBCacheByteArray
public OBCacheByteArray(OBCacheHandlerByteArray<O> handler,
int cacheSize)
throws OBException
- Initialize the cache with the given amount of elements.
- Parameters:
size
- Number of elements that the internal hash table will be
initialized with.
- Throws:
OBException
get
public O get(byte[] id)
throws OBException,
InstantiationException,
IllegalAccessException
- Gets the given object, returns null if the object is not found.
- Parameters:
id
- internal id.
- Returns:
- null if no object is found
- Throws:
OBException
InstantiationException
IllegalAccessException
exists
public boolean exists(byte[] id)
put
public void put(byte[] id,
O object)
removeEldestEntry
protected boolean removeEldestEntry(Map.Entry<ByteArrayKey,O> eldest)
- Overrides:
removeEldestEntry
in class LinkedHashMap<ByteArrayKey,O>
clearAll
public void clearAll()
throws OBException
- Description copied from class:
AbstractOBCache
- Makes sure the cache is cleaned and each
object is stored.
- Specified by:
clearAll
in class AbstractOBCache<ByteArrayKey,O>
- Throws:
OBException
remove
public void remove(byte[] key)
- Remove the given key from the table.
- Parameters:
key
-
Copyright © 2007-2011 Arnoldo Jose Muller Molina. All Rights Reserved.