org.egothor.cache
Interface Cache<K,V>

Type Parameters:
K - type of the stored keys
V - type of the stored values
All Known Implementing Classes:
AbstractCache, ArcCache, FifoCache, LfuCache, LruCache, LruKCache, MultiQueueCache, SlruCache, StaticCache, StaticDynamicCache, TwoQueueCache

public interface Cache<K,V>

Interface representing a cache that is able to store key->value mappings. Provides methods for manipulating the cache and retrieving statistical information.


Method Summary
 int capacity()
          Returns the maximum number of key->value mappings for this cache.
 void clear()
          Remove all key->value mappings from the cache and cleans auxiliary data structures (such as history queues).
 boolean containsKey(K key)
          Checks whether the specified key is cached.
 void evict()
          Removes the next key from the cache according to the current cache replacement policy.
 V get(K key)
          Gets the value associated with the specified key from the cache if a mapping exists, or the value returned by the resolver.
 Resolver<K,V> getResolver()
          Gets the current resolver associated with this cache.
 float hitRatio()
          Returns the hits/requests ratio in percents.
 long hits()
          Returns the number of all hits.
 java.util.Set<K> keySet()
          Gets all keys contained in the cache.
 long misses()
          Returns the number of all misses.
 K nextEvicted()
          Gets the next key that would be removed from the cache according to the current cache replacement policy.
 V put(K key, V value)
          Adds a new key->value mapping to the cache.
 V remove(K key)
          Removes the specified key and its value from the cache.
 long requests()
          Returns the number of all submitted requests
 void resetCounters()
          Sets hits and misses counters to zero.
 Resolver<K,V> setResolver(Resolver<K,V> resolver)
          Sets the resolver associated with this cache.
 int size()
          Returns the number of key->value mappings in the cache.
 V update(K key, V value)
          Updates the value associated with the specified key in the cache if a mapping exists for the key.
 

Method Detail

put

V put(K key,
      V value)
Adds a new key->value mapping to the cache. If a mapping previously existed for the specified key, it is removed at first. If the cache is full, a mapping is removed from the cache according to the current eviction policy.

Parameters:
key - key to add to the cache
value - value to map the key on
Returns:
previous value associated with the key or null if a previous mapping did not exists in the cache for the specified key

get

V get(K key)
Gets the value associated with the specified key from the cache if a mapping exists, or the value returned by the resolver.

Parameters:
key - key to get the value for
Returns:
value associated with the key from the cache, or from the resolver if a mapping does not exits in the cache

remove

V remove(K key)
Removes the specified key and its value from the cache.

Parameters:
key - key to remove from the cache.
Returns:
value associated with the key, or null if a mapping did not exist

update

V update(K key,
         V value)
Updates the value associated with the specified key in the cache if a mapping exists for the key.

Parameters:
key - key to change the value for
value - new value associated with the key
Returns:
previous associated value or null if the key is not cached

containsKey

boolean containsKey(K key)
Checks whether the specified key is cached.

Parameters:
key - key to check
Returns:
true, if the key is currently cached, false otherwise

clear

void clear()
Remove all key->value mappings from the cache and cleans auxiliary data structures (such as history queues).


keySet

java.util.Set<K> keySet()
Gets all keys contained in the cache.

Returns:
Set of keys contained in the cache.

size

int size()
Returns the number of key->value mappings in the cache.

Returns:
number of key->value mappings in the cache

nextEvicted

K nextEvicted()
Gets the next key that would be removed from the cache according to the current cache replacement policy.

Returns:
key, that would be removed next from the cache or null if the cache is empty

evict

void evict()
Removes the next key from the cache according to the current cache replacement policy.


hitRatio

float hitRatio()
Returns the hits/requests ratio in percents.

Returns:
hit ratio of the cache

hits

long hits()
Returns the number of all hits.

Returns:
number of all hits

misses

long misses()
Returns the number of all misses.

Returns:
number of all misses

requests

long requests()
Returns the number of all submitted requests

Returns:
number of all submitted requests

capacity

int capacity()
Returns the maximum number of key->value mappings for this cache.

Returns:
maximum capacity of the cache

resetCounters

void resetCounters()
Sets hits and misses counters to zero.


getResolver

Resolver<K,V> getResolver()
Gets the current resolver associated with this cache.

Returns:
resolver associated with the cache

setResolver

Resolver<K,V> setResolver(Resolver<K,V> resolver)
Sets the resolver associated with this cache.

Parameters:
resolver - new resolver we want to associate with this cache.
Returns:
replaced resolver