velosurf.cache
Class Cache

java.lang.Object
  |
  +--velosurf.cache.Cache

public class Cache
extends java.lang.Object

Cache that keeps fetched instances in memory.

Three modes :

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

This caching mechanism is meant for straightforward optimizations in simple situations, for instance to avoid re-fetching the loggued user at each request. Please keep in mind that the cache can quickly become inconsistant if used in conjunction with complex modification queries (that occur in its back...).

Author:
Claude Brisson

Inner Class Summary
static class Cache.ArrayKey
           
 
Field Summary
static int FULL_CACHE
          constant used to specify the "full cache" mode
protected  int mCachingMethod
          The caching method this cache uses
protected  java.util.Map mInnerCache
          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 inCachingMethod)
          Cache constructor
 
Method Summary
 void clear()
          Clear the cache
 java.lang.Object get(java.lang.Object inKey)
          Try to get an instance from the cache
 void put(java.lang.Object inKey, java.lang.Object inValue)
          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, registerNatives, toString, wait, wait, wait
 

Field Detail

NO_CACHE

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

SOFT_CACHE

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

FULL_CACHE

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

mCachingMethod

protected int mCachingMethod
The caching method this cache uses

mInnerCache

protected java.util.Map mInnerCache
the inner map that stores associations
Constructor Detail

Cache

public Cache(int inCachingMethod)
Cache constructor
Parameters:
inCachingMethod - required caching mode
Method Detail

put

public void put(java.lang.Object inKey,
                java.lang.Object inValue)
Put an instance in the cache
Parameters:
inKey - key field(s) of this instance
inValue - 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 inKey)
Try to get an instance from the cache
Parameters:
inKey - key field(s) of the asked instance
Returns:
Asked instance or null if not found

clear

public void clear()
Clear the cache


ooOoo