velosurf.cache
Class Cache

java.lang.Object
  extended by velosurf.cache.Cache

public class Cache
extends java.lang.Object

Cache that keeps fetched instances in memory.

Three modes (defined for <database> or for <entity> in model.xml:

For an entity's instances to be cached, the associated table must have a primary key (even if multivalued).

Warning: Velosurf will invalidate entries on single row update and delete queries, but global updates and deletes are not taken into account.

This caching mechanism is meant for straightforward optimizations in read-only or very simple situations, for instance to avoid re-fetching data related to the logged user at each request.

Author:
Claude Brisson

Nested Class Summary
static class Cache.ArrayKey
          ArrayKey is a simple wrapper that provides a field-to-field equal method between encapsulated arrays.
 
Field Summary
private  int cachingMethod
          The caching method this cache uses.
static int FULL_CACHE
          Constant used to specify the "full cache" mode.
private  java.util.Map<java.lang.Object,java.lang.Object> innerCache
          the inner map that stores associations.
static int NO_CACHE
          Constant used to specify the "no cache" mode.
static int SOFT_CACHE
          Constant used to specify the "soft cache" mode.
 
Constructor Summary
Cache(int cachingMethod)
          Cache constructor.
 
Method Summary
 void clear()
          Clear the cache.
 java.lang.Object get(java.lang.Object key)
          Try to get an instance from the cache.
 void invalidate(java.lang.Object key)
          invalidates an entry (used after an insert or an update)
 void put(java.lang.Object key, java.lang.Object value)
          Put an instance in the cache.
 int size()
          Getter for the size of the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_CACHE

public static final int NO_CACHE
Constant used to specify the "no cache" mode.

See Also:
Constant Field Values

SOFT_CACHE

public static final int SOFT_CACHE
Constant used to specify the "soft cache" mode.

See Also:
Constant Field Values

FULL_CACHE

public static final int FULL_CACHE
Constant used to specify the "full cache" mode.

See Also:
Constant Field Values

cachingMethod

private int cachingMethod
The caching method this cache uses.


innerCache

private java.util.Map<java.lang.Object,java.lang.Object> innerCache
the inner map that stores associations.

Constructor Detail

Cache

public Cache(int cachingMethod)
Cache constructor.

Parameters:
cachingMethod - required caching mode
Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object value)
Put an instance in the cache.

Parameters:
key - key field(s) of this instance
value - instance

size

public int size()
Getter for the size of the cache.

Returns:
the size of the cache

get

public java.lang.Object get(java.lang.Object key)
Try to get an instance from the cache.

Parameters:
key - key field(s) of the asked instance
Returns:
Asked instance or null if not found

clear

public void clear()
Clear the cache.


invalidate

public void invalidate(java.lang.Object key)
invalidates an entry (used after an insert or an update)



~ooOoo~