|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.opengts.extra.util.MemCache<KEY,VAL>
public class MemCache<KEY,VAL>
A simple memory cache handler
Nested Class Summary | |
---|---|
class |
MemCache.MemCacheMap<KEY,VAL>
Class MemCachMap |
static class |
MemCache.MemEntry<KEY,VAL>
Class MemEntry |
static class |
MemCache.MemEntryComparator<KEY,VAL>
Class MemEntryComparator (used for debugging only) |
Field Summary | |
---|---|
static int |
DEFAULT_CACHE_SIZE
|
static double |
DEFAULT_TRIM_PERCENT
|
static int |
DEFAULT_TRIM_SIZE
|
static double |
MAX_MEMORY_UTILIZATION
|
static long |
MAXIMUM_CACHE_AGE_MS
|
static int |
MINIMUM_CACHE_SIZE
|
Constructor Summary | |
---|---|
MemCache()
Constructor |
|
MemCache(int maxSize)
Constructor |
Method Summary | |
---|---|
void |
addValue(KEY key,
VAL val)
Add entry to cache |
boolean |
exceedsMaximumCacheSize(double maxGain)
Returns true if the current size exceeds the maximum cache size |
int |
getMaximumCacheSize()
Gets the maximum cache size |
int |
getMaximumCacheSizeCutbackCount()
Returns the number of size cutbacks performed on the cache which were caused by excessive memory usage. |
long |
getMaximumEntryAgeMS()
Gets the maximum age of a cached entry (in milliseconds) |
int |
getSize()
Gets the current size of the memory-cache |
boolean |
getTrimOnAdd()
Gets the trim-on-add state |
VAL |
getValue(KEY key)
Get entry from cache |
VAL |
getValue(KEY key,
VAL dft)
Get entry from cache |
boolean |
hasValue(KEY key)
Returns true if the specified key exists in the cache |
static void |
main(java.lang.String[] argv)
|
int |
setMaximumCacheSize(int maxSize)
Sets the maximum cache size |
long |
setMaximumEntryAgeMS(long maxAgeMS)
Sets the maximum age of a cached entry (in milliseconds) |
void |
setTrimOnAdd(boolean toa)
Sets the trim-on-add state |
java.lang.String |
toString()
Gets a String representation of the contents of this MemCache. |
void |
trimCache()
Remove old/excessive entries in cache |
void |
trimCache(java.lang.String msg)
Remove old/excessive entries in cache |
static int |
TrimSize(int size)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MINIMUM_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZE
public static final long MAXIMUM_CACHE_AGE_MS
public static final double DEFAULT_TRIM_PERCENT
public static final int DEFAULT_TRIM_SIZE
public static final double MAX_MEMORY_UTILIZATION
Constructor Detail |
---|
public MemCache()
public MemCache(int maxSize)
Method Detail |
---|
public static int TrimSize(int size)
public int getSize()
public int setMaximumCacheSize(int maxSize)
setMaximumCacheSize
in interface MemCacheAPI<KEY,VAL>
maxSize
- The maximum cache size
public int getMaximumCacheSize()
getMaximumCacheSize
in interface MemCacheAPI<KEY,VAL>
public boolean exceedsMaximumCacheSize(double maxGain)
maxGain
- The gain/percentage to apply to the max cache size
public long setMaximumEntryAgeMS(long maxAgeMS)
maxAgeMS
- The maximum age of a cached entry (in milliseconds)
public long getMaximumEntryAgeMS()
public int getMaximumCacheSizeCutbackCount()
public void setTrimOnAdd(boolean toa)
public boolean getTrimOnAdd()
public void trimCache(java.lang.String msg)
public void trimCache()
public void addValue(KEY key, VAL val)
addValue
in interface MemCacheAPI<KEY,VAL>
key
- The key to addval
- The value to associate with the specified keypublic boolean hasValue(KEY key)
hasValue
in interface MemCacheAPI<KEY,VAL>
key
- The key to check for existence
public VAL getValue(KEY key)
key
- The key of the value to retrieve
public VAL getValue(KEY key, VAL dft)
getValue
in interface MemCacheAPI<KEY,VAL>
key
- The key of the value to retrievedft
- The default value if the key does not exist
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] argv)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |