rabbit.cache
Interface Cache<K,V>

Type Parameters:
K - the key type of the cache
V - the data resource
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.
 CacheConfiguration getCacheConfiguration()
          Get the cache configuration for this cache.
 long getCurrentSize()
          Get the current size of the cache
 Iterable<? extends CacheEntry<K,V>> getEntries()
          Get the CacheEntries in the cache.
 CacheEntry<K,V> getEntry(K k)
          Get the CacheEntry assosiated with given object.
 File getEntryName(long id, boolean real, String extension)
          Get the file name for a cache entry.
 Logger getLogger()
          Get the logger of 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 start()
          Start this cache.
 void stop()
          Stop this cache.
 

Method Detail

start

void start()
Start this cache. This must be called to ensure that cleaner threads or similar are up and running.


stop

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


getCacheConfiguration

CacheConfiguration getCacheConfiguration()
Get the cache configuration for this cache.

Returns:
the current configuration of the cache

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.

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 - upon failure to get the key

getEntryName

File 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.
Returns:
the file for the new entry

newEntry

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

Parameters:
k - the key for the CacheEntry.
Returns:
a new CacheEntry initialized for the cache.
Throws:
CacheException - upon failure to reserve a new entry.

addEntry

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

Parameters:
ent - the CacheEntry to store.
Throws:
CacheException - if adding the entry fails

entryChanged

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

Parameters:
ent - the CacheEntry that changed
newKey - the new key of the entry
newValue - the new value
Throws:
CacheException - if updating the cache fails

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 - if removal fails

clear

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

Throws:
CacheException - if the clear operation failed

getEntries

Iterable<? 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.


getLogger

Logger getLogger()
Get the logger of this cache

Returns:
the Logger used by the cache