com.j256.ormlite.dao.ObjectCache Maven / Gradle / Ivy
package com.j256.ormlite.dao;
/**
* Definition of an object cache that can be injected into the Dao with the {@link Dao#setObjectCache(ObjectCache)}.
*
*
* NOTE: Most of the below methods take a Class argument but your cache can be for a single cache. If this is the
* case then you should protect against storing different classes in the cache.
*
*
* @author graywatson
*/
public interface ObjectCache {
/**
* Register a class for use with this class. This will be called before any other method for the particular class is
* called.
*/
public void registerClass(Class clazz);
/**
* Lookup in the cache for an object of a certain class that has a certain id.
*
* @return The found object or null if none.
*/
public T get(Class clazz, ID id);
/**
* Put an object in the cache that has a certain class and id.
*/
public void put(Class clazz, ID id, T data);
/**
* Delete from the cache an object of a certain class that has a certain id.
*/
public void remove(Class clazz, ID id);
/**
* Change the id in the cache for an object of a certain class from an old-id to a new-id.
*/
public T updateId(Class clazz, ID oldId, ID newId);
/**
* Remove all entries from the cache of a certain class.
*/
public void clear(Class clazz);
/**
* Remove all entries from the cache of all classes.
*/
public void clearAll();
/**
* Return the number of elements in the cache.
*/
public int size(Class clazz);
/**
* Return the number of elements in all of the caches.
*/
public int sizeAll();
}