com.j256.ormlite.dao
Class LruObjectCache

java.lang.Object
  extended by com.j256.ormlite.dao.LruObjectCache
All Implemented Interfaces:
ObjectCache

public class LruObjectCache
extends Object
implements ObjectCache

Cache for ORMLite which stores a certain number of items for each Class. Inserting an object into the cache once it is full will cause the least-recently-used object to be ejected. They can be injected into a dao with the Dao.setObjectCache(ObjectCache).

NOTE: If you set the capacity to be 100 then each Class will allow 100 items in the cache. If you have 5 classes then the cache will hold 500 objects.

Author:
graywatson

Constructor Summary
LruObjectCache(int capacity)
           
 
Method Summary
<T> void
clear(Class<T> clazz)
          Remove all entries from the cache of a certain class.
 void clearAll()
          Remove all entries from the cache of all classes.
<T,ID> T
get(Class<T> clazz, ID id)
          Lookup in the cache for an object of a certain class that has a certain id.
<T,ID> void
put(Class<T> clazz, ID id, T data)
          Put an object in the cache that has a certain class and id.
<T> void
registerClass(Class<T> clazz)
          Register a class for use with this class.
<T,ID> void
remove(Class<T> clazz, ID id)
          Delete from the cache an object of a certain class that has a certain id.
<T> int
size(Class<T> clazz)
          Return the number of elements in the cache.
 int sizeAll()
          Return the number of elements in all of the caches.
<T,ID> T
updateId(Class<T> clazz, ID oldId, ID newId)
          Change the id in the cache for an object of a certain class from an old-id to a new-id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LruObjectCache

public LruObjectCache(int capacity)
Method Detail

registerClass

public <T> void registerClass(Class<T> clazz)
Description copied from interface: ObjectCache
Register a class for use with this class. This will be called before any other method for the particular class is called.

Specified by:
registerClass in interface ObjectCache

get

public <T,ID> T get(Class<T> clazz,
                    ID id)
Description copied from interface: ObjectCache
Lookup in the cache for an object of a certain class that has a certain id.

Specified by:
get in interface ObjectCache
Returns:
The found object or null if none.

put

public <T,ID> void put(Class<T> clazz,
                       ID id,
                       T data)
Description copied from interface: ObjectCache
Put an object in the cache that has a certain class and id.

Specified by:
put in interface ObjectCache

clear

public <T> void clear(Class<T> clazz)
Description copied from interface: ObjectCache
Remove all entries from the cache of a certain class.

Specified by:
clear in interface ObjectCache

clearAll

public void clearAll()
Description copied from interface: ObjectCache
Remove all entries from the cache of all classes.

Specified by:
clearAll in interface ObjectCache

remove

public <T,ID> void remove(Class<T> clazz,
                          ID id)
Description copied from interface: ObjectCache
Delete from the cache an object of a certain class that has a certain id.

Specified by:
remove in interface ObjectCache

updateId

public <T,ID> T updateId(Class<T> clazz,
                         ID oldId,
                         ID newId)
Description copied from interface: ObjectCache
Change the id in the cache for an object of a certain class from an old-id to a new-id.

Specified by:
updateId in interface ObjectCache

size

public <T> int size(Class<T> clazz)
Description copied from interface: ObjectCache
Return the number of elements in the cache.

Specified by:
size in interface ObjectCache

sizeAll

public int sizeAll()
Description copied from interface: ObjectCache
Return the number of elements in all of the caches.

Specified by:
sizeAll in interface ObjectCache


This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.