Top Description Fields Constructors Methods
org.h2.util

public Class CacheLRU

extends Object
implements Cache
Class Inheritance
All Implemented Interfaces
org.h2.util.Cache
Imports
java.util.ArrayList, .Collections, .Map, org.h2.engine.Constants, .SysProperties, org.h2.message.DbException

A cache implementation based on the last recently used (LRU) algorithm.

Field Summary

Modifier and TypeField and Description
private final boolean
fifo

Use First-In-First-Out (don't move recently used items to the front of the queue).

private final CacheObject
private final int
len

The number of cache buckets.

private final int
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
pack-priv static final String
private CacheObject[]
private final CacheWriter

Constructor Summary

AccessConstructor and Description
pack-priv
CacheLRU(CacheWriter writer, int maxMemoryKb, boolean fifo)

Method Summary

Modifier and TypeMethod and Description
private void
public void
clear()

Implements org.h2.util.Cache.clear.

Clear the cache.

public CacheObject
find(int
the unique key of the element
pos
)

Implements org.h2.util.Cache.find.

Get an element from the cache if it is available.

public CacheObject
get(int
the unique key of the element
pos
)

Implements org.h2.util.Cache.get.

Get an element in the cache if it is available.

public ArrayList<CacheObject>
getAllChanged()

Implements org.h2.util.Cache.getAllChanged.

Get all objects in the cache that have been changed.

public static Cache

Returns:

the cache object
getCache
(CacheWriter
the cache writer
writer
,
String
the cache type
cacheType
,
int
the size
cacheSize
)

Create a cache of the given type and size.

public int
getMaxMemory()

Implements org.h2.util.Cache.getMaxMemory.

Get the maximum memory to be used.

public int
getMemory()

Implements org.h2.util.Cache.getMemory.

Get the used size in KB.

public void
put(CacheObject
the object
rec
)

Implements org.h2.util.Cache.put.

Add an element to the cache.

public boolean
remove(int
the unique key of the element
pos
)

Implements org.h2.util.Cache.remove.

Remove an object from the cache.

private void
private void
private void
public void
setMaxMemory(int
the maximum size in KB
maxKb
)

Implements org.h2.util.Cache.setMaxMemory.

Set the maximum memory to be used by this cache.

public CacheObject
update(int
the unique key of the element
pos
,
CacheObject
the element
rec
)

Implements org.h2.util.Cache.update.

Update an element in the cache.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fifoback to summary
private final boolean fifo

Use First-In-First-Out (don't move recently used items to the front of the queue).

lenback to summary
private final int len

The number of cache buckets.

maskback to summary
private final int mask
maxMemoryback to summary
private long maxMemory

The maximum memory, in words (4 bytes each).

memoryback to summary
private long memory

The current memory used in this cache, in words (4 bytes each).

recordCountback to summary
private int recordCount
TYPE_NAMEback to summary
pack-priv static final String TYPE_NAME
valuesback to summary
private CacheObject[] values
writerback to summary
private final CacheWriter writer

Constructor Detail

CacheLRUback to summary
pack-priv CacheLRU(CacheWriter writer, int maxMemoryKb, boolean fifo)

Method Detail

addToFrontback to summary
private void addToFront(CacheObject rec)
clearback to summary
public void clear()

Implements org.h2.util.Cache.clear.

Doc from org.h2.util.Cache.clear.

Clear the cache.

Annotations
@Override
findback to summary
public CacheObject find(int pos)

Implements org.h2.util.Cache.find.

Doc from org.h2.util.Cache.find.

Get an element from the cache if it is available. This will not move the item to the front of the list.

Parameters
pos:int

the unique key of the element

Returns:CacheObject

the element or null

Annotations
@Override
getback to summary
public CacheObject get(int pos)

Implements org.h2.util.Cache.get.

Doc from org.h2.util.Cache.get.

Get an element in the cache if it is available. This will move the item to the front of the list.

Parameters
pos:int

the unique key of the element

Returns:CacheObject

the element or null

Annotations
@Override
getAllChangedback to summary
public ArrayList<CacheObject> getAllChanged()

Implements org.h2.util.Cache.getAllChanged.

Doc from org.h2.util.Cache.getAllChanged.

Get all objects in the cache that have been changed.

Returns:ArrayList<CacheObject>

the list of objects

Annotations
@Override
getCacheback to summary
public static Cache getCache(CacheWriter writer, String cacheType, int cacheSize)

Create a cache of the given type and size.

Parameters
writer:CacheWriter

the cache writer

cacheType:String

the cache type

cacheSize:int

the size

Returns:Cache

the cache object

getMaxMemoryback to summary
public int getMaxMemory()

Implements org.h2.util.Cache.getMaxMemory.

Doc from org.h2.util.Cache.getMaxMemory.

Get the maximum memory to be used.

Returns:int

the maximum size in KB

Annotations
@Override
getMemoryback to summary
public int getMemory()

Implements org.h2.util.Cache.getMemory.

Doc from org.h2.util.Cache.getMemory.

Get the used size in KB.

Returns:int

the current size in KB

Annotations
@Override
putback to summary
public void put(CacheObject rec)

Implements org.h2.util.Cache.put.

Doc from org.h2.util.Cache.put.

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.

Parameters
rec:CacheObject

the object

Annotations
@Override
removeback to summary
public boolean remove(int pos)

Implements org.h2.util.Cache.remove.

Doc from org.h2.util.Cache.remove.

Remove an object from the cache.

Parameters
pos:int

the unique key of the element

Returns:boolean

true if the key was in the cache

Annotations
@Override
removeFromLinkedListback to summary
private void removeFromLinkedList(CacheObject rec)
removeOldback to summary
private void removeOld()
removeOldIfRequiredback to summary
private void removeOldIfRequired()
setMaxMemoryback to summary
public void setMaxMemory(int maxKb)

Implements org.h2.util.Cache.setMaxMemory.

Doc from org.h2.util.Cache.setMaxMemory.

Set the maximum memory to be used by this cache.

Parameters
maxKb:int

the maximum size in KB

Annotations
@Override
updateback to summary
public CacheObject update(int pos, CacheObject rec)

Implements org.h2.util.Cache.update.

Doc from org.h2.util.Cache.update.

Update an element in the cache. This will move the item to the front of the list.

Parameters
pos:int

the unique key of the element

rec:CacheObject

the element

Returns:CacheObject

the element

Annotations
@Override