rabbit.cache
Interface Cache<K,V>

All Known Implementing Classes:
NCache

public interface Cache<K,V>

A cache, mostly works like a map in lookup, insert and delete. A cache may be persistent over sessions. A cache may clean itself over time.

Author:
Robert Olofsson

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 newValue)
          Signal that a cache entry have changed.
 void flush()
          Make sure that the cache is written to the disk.
 URL getCacheDir()
          Get the location where this cache stores its files.
 long getCacheTime()
          Get the number of miliseconds the cache stores things usually.
 long getCurrentSize()
          Get the current size of the cache
 Collection<? extends CacheEntry<K,V>> getEntries()
          Get the CacheEntries in the cache.
 CacheEntry<K,V> getEntry(K k)
          Get the CacheEntry assosiated with given object.
 String getEntryName(long id, boolean real, 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.
 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 o from the cache.
 void setCacheTime(long newCacheTime)
          Set the standard expiry-time for CacheEntries
 void setMaxSize(long newMaxSize)
          Set the maximum size for this cache.
 void stop()
          Stop this cache.
 

Method Detail

getMaxSize

long getMaxSize()
Get the maximum size for this cache.

Returns:
the maximum size in bytes this cache.

setMaxSize

void setMaxSize(long newMaxSize)
Set the maximum size for this cache.

Parameters:
newMaxSize - the new maximum size for the cache.

getCacheTime

long getCacheTime()
Get the number of miliseconds the cache stores things usually. This is the standard expiretime for objects, but you can set it for CacheEntries individially if you want to. NOTE 1: dont trust that an object will be in the cache this long. NOTE 2: dont trust that an object will be removed from the cache when it expires.

Returns:
the number of miliseconds objects are stored normally.

setCacheTime

void setCacheTime(long newCacheTime)
Set the standard expiry-time for CacheEntries

Parameters:
newCacheTime - the number of miliseconds to keep objects normally.

getCurrentSize

long getCurrentSize()
Get the current size of the cache

Returns:
the current size of the cache in bytes.

getNumberOfEntries

long getNumberOfEntries()
Get the current number of entries in the cache.

Returns:
the current number of entries in the cache.

getCacheDir

URL getCacheDir()
Get the location where this cache stores its files.

Returns:
the location, null if no physical location is used.

getEntry

CacheEntry<K,V> getEntry(K k)
                         throws CacheException
Get the CacheEntry assosiated with given object.

Parameters:
k - the key.
Returns:
the NCacheEntry or null (if not found).
Throws:
CacheException

getEntryName

String getEntryName(long id,
                    boolean real,
                    String extension)
Get the file name for a cache entry.

Parameters:
id - the id of the cache entry
real - false if this is a temporary cache file, true if it is a realized entry.
extension - the cache entry extension.

getKeyFileHandler

FileHandler<K> getKeyFileHandler()
Get the file handler for the keys.


getHookFileHandler

FileHandler<V> getHookFileHandler()
Get the file handler for the values.


newEntry

CacheEntry<K,V> newEntry(K k)
Reserve space for a CacheEntry with key o.

Parameters:
k - the key for the CacheEntry.
Returns:
a new CacheEntry initialized for the cache.

addEntry

void addEntry(CacheEntry<K,V> ent)
              throws CacheException
Insert a CacheEntry into the cache.

Parameters:
ent - the CacheEntry to store.
Throws:
CacheException

entryChanged

void entryChanged(CacheEntry<K,V> ent,
                  K newKey,
                  V newValue)
                  throws CacheException
Signal that a cache entry have changed.

Throws:
CacheException

remove

void remove(K k)
            throws CacheException
Remove the Entry with key o from the cache.

Parameters:
k - the key for the CacheEntry.
Throws:
CacheException

clear

void clear()
           throws CacheException
Clear the Cache from files.

Throws:
CacheException

getEntries

Collection<? extends CacheEntry<K,V>> getEntries()
Get the CacheEntries in the cache.

Returns:
an Enumeration of the CacheEntries.

flush

void flush()
Make sure that the cache is written to the disk.


stop

void stop()
Stop this cache. If this cache is using any cleaner threads they have to be stopped when this method is called.


getLogger

Logger getLogger()
Get the logger of this cache