org.h2.util
Class CacheLRU

java.lang.Object
  extended by org.h2.util.CacheLRU
All Implemented Interfaces:
Cache

public class CacheLRU
extends java.lang.Object
implements Cache

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


Method Summary
 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.
 ObjectArray<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 getMaxSize()
          Get the maximum size in words (4 bytes).
 int getSize()
          Get the used size in words (4 bytes).
 java.lang.String getTypeName()
          Get the name of the cache type in a human readable form.
 void put(CacheObject rec)
          Add an element to the cache.
 void remove(int pos)
          Remove an object from the cache.
 void setMaxSize(int maxKb)
          Set the maximum memory to be used by this cache.
 CacheObject update(int pos, CacheObject rec)
          Update an element in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCache

public static Cache getCache(CacheWriter writer,
                             java.lang.String cacheType,
                             int cacheSize)
                      throws java.sql.SQLException
Create a cache of the given type and size.

Parameters:
writer - the cache writer
cacheType - the cache type
cacheSize - the size
Returns:
the cache object
Throws:
java.sql.SQLException

clear

public void clear()
Description copied from interface: Cache
Clear the cache.

Specified by:
clear in interface Cache

put

public void put(CacheObject rec)
         throws java.sql.SQLException
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.

Specified by:
put in interface Cache
Parameters:
rec - the object
Throws:
java.sql.SQLException

update

public CacheObject update(int pos,
                          CacheObject rec)
                   throws java.sql.SQLException
Description copied from interface: Cache
Update an element in the cache. This will move the item to the front of the list.

Specified by:
update in interface Cache
Parameters:
pos - the unique key of the element
rec - the element
Returns:
the element
Throws:
java.sql.SQLException

remove

public void remove(int pos)
Description copied from interface: Cache
Remove an object from the cache.

Specified by:
remove in interface Cache
Parameters:
pos - the unique key of the element

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.

Specified by:
find in interface Cache
Parameters:
pos - the unique key of the element
Returns:
the element or null

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.

Specified by:
get in interface Cache
Parameters:
pos - the unique key of the element
Returns:
the element or null

getAllChanged

public ObjectArray<CacheObject> getAllChanged()
Description copied from interface: Cache
Get all objects in the cache that have been changed.

Specified by:
getAllChanged in interface Cache
Returns:
the list of objects

setMaxSize

public void setMaxSize(int maxKb)
                throws java.sql.SQLException
Description copied from interface: Cache
Set the maximum memory to be used by this cache.

Specified by:
setMaxSize in interface Cache
Parameters:
maxKb - in number of double words (4 bytes)
Throws:
java.sql.SQLException

getTypeName

public java.lang.String getTypeName()
Description copied from interface: Cache
Get the name of the cache type in a human readable form.

Specified by:
getTypeName in interface Cache
Returns:
the cache type name

getMaxSize

public int getMaxSize()
Description copied from interface: Cache
Get the maximum size in words (4 bytes).

Specified by:
getMaxSize in interface Cache
Returns:
the maximum size in number of double words (4 bytes)

getSize

public int getSize()
Description copied from interface: Cache
Get the used size in words (4 bytes).

Specified by:
getSize in interface Cache
Returns:
the current size in number of double words (4 bytes)