package org.mongodb.morphia.mapping.cache;


import org.mongodb.morphia.Key;

A primarily internal class used by MorphiaIterator to track entities loaded from mongo to prevent multiple loads of objects when keys are seen multiple times in a query result.
/** * A primarily internal class used by MorphiaIterator to track entities loaded from mongo to prevent multiple loads of objects when keys * are * seen multiple times in a query result. */
public interface EntityCache {
Looks for a Key in the cache
Params:
  • k – the Key to search for
Returns:true if the Key is found
/** * Looks for a Key in the cache * * @param k the Key to search for * @return true if the Key is found */
Boolean exists(Key<?> k);
Clears the cache
/** * Clears the cache */
void flush();
Returns the entity for a Key
Params:
  • k – the Key to search for
Type parameters:
  • <T> – the type of the entity
Returns:the entity
/** * Returns the entity for a Key * * @param k the Key to search for * @param <T> the type of the entity * @return the entity */
<T> T getEntity(Key<T> k);
Returns a proxy for the entity for a Key
Params:
  • k – the Key to search for
Type parameters:
  • <T> – the type of the entity
Returns:the proxy
/** * Returns a proxy for the entity for a Key * * @param k the Key to search for * @param <T> the type of the entity * @return the proxy */
<T> T getProxy(Key<T> k);
Notifies the cache of the existence of a Key
Params:
  • k – the Key
  • exists – true if the Key represents an existing entity
/** * Notifies the cache of the existence of a Key * * @param k the Key * @param exists true if the Key represents an existing entity */
void notifyExists(Key<?> k, boolean exists);
Adds an entity to the cache
Params:
  • k – the Key of the entity
  • t – the entity
Type parameters:
  • <T> – the type of the entity
/** * Adds an entity to the cache * * @param k the Key of the entity * @param t the entity * @param <T> the type of the entity */
<T> void putEntity(Key<T> k, T t);
Adds a proxy to the cache
Params:
  • k – the Key of the entity
  • t – the proxy
Type parameters:
  • <T> – the type of the entity
/** * Adds a proxy to the cache * * @param k the Key of the entity * @param t the proxy * @param <T> the type of the entity */
<T> void putProxy(Key<T> k, T t);
Returns:the stats for this cache
/** * @return the stats for this cache */
EntityCacheStatistics stats(); }