Package org.h2.util
Class CacheLRU
- java.lang.Object
-
- org.h2.util.CacheLRU
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
fifo
Use First-In-First-Out (don't move recently used items to the front of the queue).private CacheObject
head
private int
len
The number of cache buckets.private int
mask
private long
maxMemory
The maximum memory, in words (4 bytes each).private long
memory
The current memory used in this cache, in words (4 bytes each).private int
recordCount
(package private) static java.lang.String
TYPE_NAME
private CacheObject[]
values
private CacheWriter
writer
-
Constructor Summary
Constructors Constructor Description CacheLRU(CacheWriter writer, int maxMemoryKb, boolean fifo)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addToFront(CacheObject rec)
void
clear()
Clear the cache.CacheObject
find(int pos)
Get an element from the cache if it is available.CacheObject
get(int pos)
Get an element in the cache if it is available.java.util.ArrayList<CacheObject>
getAllChanged()
Get all objects in the cache that have been changed.static Cache
getCache(CacheWriter writer, java.lang.String cacheType, int cacheSize)
Create a cache of the given type and size.int
getMaxMemory()
Get the maximum memory to be used.int
getMemory()
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
removeFromLinkedList(CacheObject rec)
private void
removeOld()
private void
removeOldIfRequired()
void
setMaxMemory(int maxKb)
Set the maximum memory to be used by this cache.CacheObject
update(int pos, CacheObject rec)
Update an element in the cache.
-
-
-
Field Detail
-
TYPE_NAME
static final java.lang.String TYPE_NAME
- See Also:
- Constant Field Values
-
writer
private final CacheWriter writer
-
fifo
private final boolean fifo
Use First-In-First-Out (don't move recently used items to the front of the queue).
-
head
private final CacheObject head
-
mask
private final int mask
-
values
private CacheObject[] values
-
recordCount
private int recordCount
-
len
private final int len
The number of cache buckets.
-
maxMemory
private long maxMemory
The maximum memory, in words (4 bytes each).
-
memory
private long memory
The current memory used in this cache, in words (4 bytes each).
-
-
Constructor Detail
-
CacheLRU
CacheLRU(CacheWriter writer, int maxMemoryKb, boolean fifo)
-
-
Method Detail
-
getCache
public static Cache getCache(CacheWriter writer, java.lang.String cacheType, int cacheSize)
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
public void put(CacheObject rec)
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
public CacheObject update(int pos, CacheObject rec)
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
private void addToFront(CacheObject rec)
-
removeFromLinkedList
private void removeFromLinkedList(CacheObject rec)
-
remove
public boolean remove(int pos)
Description copied from interface:Cache
Remove an object from the cache.
-
find
public CacheObject find(int pos)
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
public CacheObject get(int pos)
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
public java.util.ArrayList<CacheObject> 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
-
-