Package org.h2.util
Class CacheLRU
java.lang.Object
org.h2.util.CacheLRU
- All Implemented Interfaces:
Cache
A cache implementation based on the last recently used (LRU) algorithm.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
Use First-In-First-Out (don't move recently used items to the front of the queue).private final CacheObject
private final int
The number of cache buckets.private final int
private long
The maximum memory, in words (4 bytes each).private long
The current memory used in this cache, in words (4 bytes each).private int
(package private) static final String
private CacheObject[]
private final CacheWriter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addToFront
(CacheObject rec) void
clear()
Clear the cache.find
(int pos) Get an element from the cache if it is available.get
(int pos) Get an element in the cache if it is available.Get all objects in the cache that have been changed.static Cache
getCache
(CacheWriter writer, String cacheType, int cacheSize) Create a cache of the given type and size.int
Get the maximum memory to be used.int
Get the used size in KB.void
put
(CacheObject rec) Add an element to the cache.boolean
remove
(int pos) Remove an object from the cache.private void
private void
private void
void
setMaxMemory
(int maxKb) Set the maximum memory to be used by this cache.update
(int pos, CacheObject rec) Update an element in the cache.
-
Field Details
-
TYPE_NAME
- See Also:
-
writer
-
fifo
private final boolean fifoUse First-In-First-Out (don't move recently used items to the front of the queue). -
head
-
mask
private final int mask -
values
-
recordCount
private int recordCount -
len
private final int lenThe number of cache buckets. -
maxMemory
private long maxMemoryThe maximum memory, in words (4 bytes each). -
memory
private long memoryThe current memory used in this cache, in words (4 bytes each).
-
-
Constructor Details
-
CacheLRU
CacheLRU(CacheWriter writer, int maxMemoryKb, boolean fifo)
-
-
Method Details
-
getCache
Create a cache of the given type and size.- Parameters:
writer
- the cache writercacheType
- the cache typecacheSize
- the size- Returns:
- the cache object
-
clear
public void clear()Description copied from interface:Cache
Clear the cache. -
put
Description copied from interface:Cache
Add an element to the cache. Other items may fall out of the cache because of this. It is not allowed to add the same record twice. -
update
Description copied from interface:Cache
Update an element in the cache. This will move the item to the front of the list. -
removeOldIfRequired
private void removeOldIfRequired() -
removeOld
private void removeOld() -
addToFront
-
removeFromLinkedList
-
remove
public boolean remove(int pos) Description copied from interface:Cache
Remove an object from the cache. -
find
Description copied from interface:Cache
Get an element from the cache if it is available. This will not move the item to the front of the list. -
get
Description copied from interface:Cache
Get an element in the cache if it is available. This will move the item to the front of the list. -
getAllChanged
Description copied from interface:Cache
Get all objects in the cache that have been changed.- Specified by:
getAllChanged
in interfaceCache
- Returns:
- the list of objects
-
setMaxMemory
public void setMaxMemory(int maxKb) Description copied from interface:Cache
Set the maximum memory to be used by this cache.- Specified by:
setMaxMemory
in interfaceCache
- Parameters:
maxKb
- the maximum size in KB
-
getMaxMemory
public int getMaxMemory()Description copied from interface:Cache
Get the maximum memory to be used.- Specified by:
getMaxMemory
in interfaceCache
- Returns:
- the maximum size in KB
-
getMemory
public int getMemory()Description copied from interface:Cache
Get the used size in KB.
-