Package org.h2.util
Class CacheLRU
- java.lang.Object
-
- org.h2.util.CacheLRU
-
-
Field Summary
Fields Modifier and Type Field Description private booleanfifoUse First-In-First-Out (don't move recently used items to the front of the queue).private CacheObjectheadprivate intlenThe number of cache buckets.private intmaskprivate longmaxMemoryThe maximum memory, in words (4 bytes each).private longmemoryThe current memory used in this cache, in words (4 bytes each).private intrecordCount(package private) static java.lang.StringTYPE_NAMEprivate CacheObject[]valuesprivate CacheWriterwriter
-
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 voidaddToFront(CacheObject rec)voidclear()Clear the cache.CacheObjectfind(int pos)Get an element from the cache if it is available.CacheObjectget(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 CachegetCache(CacheWriter writer, java.lang.String cacheType, int cacheSize)Create a cache of the given type and size.intgetMaxMemory()Get the maximum memory to be used.intgetMemory()Get the used size in KB.voidput(CacheObject rec)Add an element to the cache.booleanremove(int pos)Remove an object from the cache.private voidremoveFromLinkedList(CacheObject rec)private voidremoveOld()private voidremoveOldIfRequired()voidsetMaxMemory(int maxKb)Set the maximum memory to be used by this cache.CacheObjectupdate(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:CacheClear the cache.
-
put
public void put(CacheObject rec)
Description copied from interface:CacheAdd 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:CacheUpdate 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:CacheRemove an object from the cache.
-
find
public CacheObject find(int pos)
Description copied from interface:CacheGet 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:CacheGet 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:CacheGet all objects in the cache that have been changed.- Specified by:
getAllChangedin interfaceCache- Returns:
- the list of objects
-
setMaxMemory
public void setMaxMemory(int maxKb)
Description copied from interface:CacheSet the maximum memory to be used by this cache.- Specified by:
setMaxMemoryin interfaceCache- Parameters:
maxKb- the maximum size in KB
-
getMaxMemory
public int getMaxMemory()
Description copied from interface:CacheGet the maximum memory to be used.- Specified by:
getMaxMemoryin interfaceCache- Returns:
- the maximum size in KB
-
-