|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrabbit.cache.NCache<K,V>
K
- the key type of the cacheV
- the data resourcepublic class NCache<K,V>
The NCache is like a Map in lookup/insert/delete The NCache is persistent over sessions (saves itself to disk). The NCache is selfcleaning, that is it removes old stuff.
Constructor Summary | |
---|---|
NCache(SProperties props,
FileHandler<K> fhk,
FileHandler<V> fhv)
Create a cache that uses default values. |
Method Summary | |
---|---|
void |
addEntry(CacheEntry<K,V> ent)
Insert a CacheEntry into the cache. |
void |
clear()
Clear the Cache from files. |
void |
entryChanged(CacheEntry<K,V> ent,
K newKey,
V newHook)
Signal that a cache entry have changed. |
void |
flush()
Make sure that the cache is written to the disk. |
java.net.URL |
getCacheDir()
Get the location where this cache stores its files. |
long |
getCacheTime()
Get the number of miliseconds the cache stores things usually. |
int |
getCleanLoopTime()
Get how long time the cleaner sleeps between cleanups. |
long |
getCurrentSize()
Get the current size of the cache |
java.util.Collection<rabbit.cache.NCacheEntry<K,V>> |
getEntries()
Get the CacheEntries in the cache. |
CacheEntry<K,V> |
getEntry(K k)
Get the CacheEntry assosiated with given object. |
java.lang.String |
getEntryName(long id,
boolean real,
java.lang.String extension)
Get the file name for a cache entry. |
FileHandler<V> |
getHookFileHandler()
Get the file handler for the values. |
FileHandler<K> |
getKeyFileHandler()
Get the file handler for the keys. |
java.util.logging.Logger |
getLogger()
Get the logger of this cache |
long |
getMaxSize()
Get the maximum size for this cache. |
long |
getNumberOfEntries()
Get the current number of entries in the cache. |
CacheEntry<K,V> |
newEntry(K k)
Reserve space for a CacheEntry with key o. |
void |
remove(K k)
Remove the Entry with key k from the cache. |
void |
run()
Loop in a cleaning loop. |
void |
setCacheTime(long newCacheTime)
Set the standard expiry-time for CacheEntries |
void |
setCleanLoopTime(int newCleanLoopTime)
Set how long time the cleaner sleeps between cleanups. |
void |
setMaxSize(long newMaxSize)
Set the maximum size for this cache. |
void |
setup(SProperties config)
Configure the cache system from the given config. |
void |
startCleaner()
Start the thread that cleans the cache. |
void |
stop()
Stop this cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NCache(SProperties props, FileHandler<K> fhk, FileHandler<V> fhv) throws java.io.IOException
props
- the configuration of the cachefhk
- the FileHandler for the cache keysfhv
- the FileHandler for the cache values
java.io.IOException
- if the cache file directory can not be configuredMethod Detail |
---|
public void startCleaner()
public java.net.URL getCacheDir()
Cache
getCacheDir
in interface Cache<K,V>
public long getMaxSize()
getMaxSize
in interface Cache<K,V>
public void setMaxSize(long newMaxSize)
setMaxSize
in interface Cache<K,V>
newMaxSize
- the new maximum size for the cache.public long getCacheTime()
getCacheTime
in interface Cache<K,V>
public void setCacheTime(long newCacheTime)
setCacheTime
in interface Cache<K,V>
newCacheTime
- the number of miliseconds to keep objects normally.public int getCleanLoopTime()
public void setCleanLoopTime(int newCleanLoopTime)
newCleanLoopTime
- the number of miliseconds to sleep.public long getCurrentSize()
getCurrentSize
in interface Cache<K,V>
public long getNumberOfEntries()
getNumberOfEntries
in interface Cache<K,V>
public CacheEntry<K,V> getEntry(K k) throws CacheException
getEntry
in interface Cache<K,V>
k
- the key.
CacheException
- upon failure to get the keypublic java.lang.String getEntryName(long id, boolean real, java.lang.String extension)
getEntryName
in interface Cache<K,V>
id
- the id of the cache entryreal
- false if this is a temporary cache file,
true if it is a realized entry.extension
- the cache entry extension.
public CacheEntry<K,V> newEntry(K k)
newEntry
in interface Cache<K,V>
k
- the key for the CacheEntry.
public FileHandler<K> getKeyFileHandler()
Cache
getKeyFileHandler
in interface Cache<K,V>
public FileHandler<V> getHookFileHandler()
Cache
getHookFileHandler
in interface Cache<K,V>
public void addEntry(CacheEntry<K,V> ent) throws CacheException
addEntry
in interface Cache<K,V>
ent
- the CacheEntry to store.
CacheException
- if adding the entry failspublic void entryChanged(CacheEntry<K,V> ent, K newKey, V newHook) throws CacheException
entryChanged
in interface Cache<K,V>
ent
- the CacheEntry that changednewKey
- the new key of the entrynewHook
- the new value
CacheException
- if updating the cache failspublic void remove(K k) throws CacheException
remove
in interface Cache<K,V>
k
- the key for the CacheEntry.
CacheException
- if removal failspublic void clear() throws CacheException
clear
in interface Cache<K,V>
CacheException
- if the clear operation failedpublic java.util.Collection<rabbit.cache.NCacheEntry<K,V>> getEntries()
getEntries
in interface Cache<K,V>
public void flush()
flush
in interface Cache<K,V>
public void run()
run
in interface java.lang.Runnable
public void stop()
Cache
stop
in interface Cache<K,V>
public void setup(SProperties config) throws java.io.IOException
config
- the properties describing the cache settings.
java.io.IOException
- if the new cache can not be configured correctlypublic java.util.logging.Logger getLogger()
Cache
getLogger
in interface Cache<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |