|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.sandev.basics.util.IDCacheBase
public class IDCacheBase
Provides common methods for all IDCache implementations. This class provides utilities and a framework for cache implementation using a Map, override the init method to change what kind of map is used.
The design goal of this cache is to provide something reliable that doesn't suck up a huge amount of memory. It has to be fast enough to provide a significant performance improvement over a database query, but that's not hard given that a getting anything out of the db is going to be around 5 million times slower.
Java 6 provides a ConcurrentSkipListMap which would be a pretty cool basis, but we are still running on Java 4 in spots (at the time of this writing) so that's a ways off still. For now all access just queues up from everything being synchronized.
| Field Summary | |
|---|---|
protected IDCacheCallback |
callback
The callback for this cache. |
protected java.util.Map |
map
The caching data structure. |
protected boolean |
revisionCheck
If true, then only newer revisions of a message will be accepted by put. |
protected long |
timeToLiveMillis
The time in milliseconds that an item may exist in the cache before it is subject to cleanup. |
| Constructor Summary | |
|---|---|
IDCacheBase()
Default ctor calls init |
|
| Method Summary | |
|---|---|
boolean |
checkRevisionNumber()
accessor for revisionCheck |
void |
cleanup()
Clean out any entries older than the time to live value. |
void |
clear()
Clear all entries from the cache. |
SandCollectionMessage |
find(SandQueryMessage sqm)
Return a collection of the messages in the cache matching the specified query. |
IDCacheCallback |
getCallback()
accessor for callback |
SandPersistMessage |
getInstance(long id)
Return the instance corresponding to the given id, or null if not found. |
java.util.Map |
getMap()
Return the underlying Map for this cache if available. |
SandPersistMessage[] |
getSortedItems()
Returns an array of all the items in the cache, sorted by lastAccessedTime with the oldest items first. |
CacheStats |
getStats(int nold)
Return the current use statistics for this cache |
long |
getTimeToLiveMillis()
accessor for timeToLiveMillis |
static java.lang.Object |
idToKey(long id)
We need an object to use as a key. |
void |
init()
Initialize the Map to a synchronized TreeMap. |
boolean |
putInstance(SandPersistMessage msg)
Write the given instance into the cache provided it is not null. |
SandPersistMessage |
removeInstance(long id)
Remove the given instance from the cache if it exists. |
void |
setCallback(IDCacheCallback idcc)
mutator for callback |
void |
setRevisionCheck(boolean val)
mutator for revisionCheck |
void |
setTimeToLiveMillis(long val)
mutator for timeToLiveMillis |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Map map
protected boolean revisionCheck
protected IDCacheCallback callback
protected long timeToLiveMillis
| Constructor Detail |
|---|
public IDCacheBase()
| Method Detail |
|---|
public boolean checkRevisionNumber()
public void setRevisionCheck(boolean val)
public IDCacheCallback getCallback()
getCallback in interface IDCachepublic void setCallback(IDCacheCallback idcc)
setCallback in interface IDCachepublic long getTimeToLiveMillis()
getTimeToLiveMillis in interface IDCachepublic void setTimeToLiveMillis(long val)
setTimeToLiveMillis in interface IDCachepublic boolean putInstance(SandPersistMessage msg)
putInstance in interface IDCachepublic SandPersistMessage getInstance(long id)
getInstance in interface IDCachepublic SandPersistMessage removeInstance(long id)
removeInstance in interface IDCachepublic void clear()
clear in interface IDCachepublic java.util.Map getMap()
getMap in interface IDCachepublic SandCollectionMessage find(SandQueryMessage sqm)
It is the callers responsibility to
find in interface IDCachepublic static java.lang.Object idToKey(long id)
public SandPersistMessage[] getSortedItems()
public CacheStats getStats(int nold)
getStats in interface IDCachepublic void cleanup()
cleanup in interface IDCachepublic void init()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||