public class ObjectsCache extends Object
Modifier and Type | Class and Description |
---|---|
class |
ObjectsCache.ObjectsCacheElement
Objects cache element.
|
Constructor and Description |
---|
ObjectsCache(ObjectsDB objectsDB)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addObject(long objectKey,
Object object)
Adds an object to the cache.
|
void |
addObject(long objectKey,
Object object,
boolean inDB,
boolean edited)
Adds an object to the cache.
|
void |
addObjects(HashMap<Long,Object> objects)
Adds an object to the cache.
|
void |
addObjects(HashMap<Long,Object> objects,
boolean inDB,
boolean edited)
Adds an object to the cache.
|
void |
clearCache()
Clears the cache.
|
int |
getCacheSize()
Returns the cache size in number of objects.
|
HashSet<Long> |
getClassInCache(Class className)
Returns the class type of the objects in cache.
|
double |
getMemoryShare()
Returns the share of heap size which can be used before emptying the
cache.
|
Object |
getObject(long objectKey)
Returns the objects if present in the cache.
|
boolean |
inCache(long longKey)
Check if key in cache.
|
boolean |
isEmpty()
Indicates whether the cache is empty.
|
void |
removeObject(long objectKey)
Removes an object from the cache.
|
void |
saveCache(WaitingHandler waitingHandler,
boolean emptyCache)
Saves the cache content in the database.
|
void |
saveObjects(int numLastEntries)
Saves an entry in the database if modified and clears it from the cache.
|
void |
saveObjects(int numLastEntries,
WaitingHandler waitingHandler,
boolean clearEntries)
Saves an entry in the database if modified.
|
void |
setMemoryShare(double memoryShare)
Sets the share of heap size which can be used before emptying the cache.
|
void |
setReadOnly(boolean readOnly)
Sets the cache in read only.
|
public ObjectsCache(ObjectsDB objectsDB)
objectsDB
- the object databasepublic int getCacheSize()
public double getMemoryShare()
public void setMemoryShare(double memoryShare)
memoryShare
- the share of heap size which can be used before
emptying the cachepublic Object getObject(long objectKey)
objectKey
- the key of the objectpublic void removeObject(long objectKey)
objectKey
- the key of the objectpublic void addObject(long objectKey, Object object)
objectKey
- the key of the objectobject
- the object to store in the cachepublic void addObject(long objectKey, Object object, boolean inDB, boolean edited)
objectKey
- the key of the objectobject
- the object to store in the cacheinDB
- the database stateedited
- the edited statepublic void addObjects(HashMap<Long,Object> objects)
objects
- the key / objects to store in the cachepublic void addObjects(HashMap<Long,Object> objects, boolean inDB, boolean edited)
objects
- the key / objects to store in the cacheinDB
- their database stateedited
- their editing statepublic void saveObjects(int numLastEntries)
numLastEntries
- number of keys of the entriespublic void saveObjects(int numLastEntries, WaitingHandler waitingHandler, boolean clearEntries)
numLastEntries
- number of keys of the entrieswaitingHandler
- a waiting handler displaying progress to the user.
Can be null. Progress will be displayed as secondary.clearEntries
- a boolean indicating whether the entry shall be
cleared from the cachepublic boolean inCache(long longKey)
longKey
- key of the entrypublic void saveCache(WaitingHandler waitingHandler, boolean emptyCache)
waitingHandler
- a waiting handler on which the progress will be
displayedemptyCache
- boolean indicating whether the cache content shall be
cleared while saving displayed as secondary progress. Can be null.public boolean isEmpty()
public void clearCache()
public void setReadOnly(boolean readOnly)
readOnly
- boolean indicating whether the cache should be in read
onlyCopyright © 2021. All rights reserved.