|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.egothor.cache.AbstractCache<K,V>
K
- type of the keyV
- type of the valuepublic abstract class AbstractCache<K,V>
An abstract implementation of Cache
that provides some common methods for cache classes.
Field Summary | |
---|---|
protected int |
capacity
Capacity of this cache. |
static int |
DEFAULT_CAPACITY
Default capacity of the cache if no explicit capacity is provided. |
protected long |
hits
Number of successful get requests. |
protected long |
misses
Number of unsuccessful get requests. |
protected Resolver<K,V> |
resolver
Object implementing Resolver interface that can be used to retrieve the value for the specified key in case of a cache miss. |
Constructor Summary | |
---|---|
protected |
AbstractCache(Resolver<K,V> resolver,
int capacity)
Constructor for the AbstractCache object. |
Method Summary | |
---|---|
int |
capacity()
Returns the maximum number of key->value mappings for this cache. |
abstract boolean |
containsKey(K key)
Checks whether the specified key is cached. |
abstract void |
evict()
Removes the next key from the cache according to the current cache replacement policy. |
V |
get(K key)
Checks whether key parameter is not null. |
Resolver<K,V> |
getResolver()
Gets the current resolver associated with this cache. |
float |
hitRatio()
Computes the hits/requests ratio in percents. |
long |
hits()
Returns the number of all hits. |
long |
misses()
Returns the number of all misses. |
abstract 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)
Checks whether key and value parameters are not null. |
V |
remove(K key)
Checks whether key parameter is not null. |
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. |
abstract int |
size()
Returns the number of key->value mappings in the cache. |
abstract java.lang.String |
toString()
|
V |
update(K key,
V value)
Checks whether key and value parameters are not null. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.egothor.cache.Cache |
---|
clear, keySet |
Field Detail |
---|
public static final int DEFAULT_CAPACITY
protected int capacity
protected long hits
protected long misses
protected Resolver<K,V> resolver
Constructor Detail |
---|
protected AbstractCache(Resolver<K,V> resolver, int capacity) throws java.lang.IllegalArgumentException
NullResolver
if no resolver was specified.
resolver
- resolver that will be associated with the cachecapacity
- capacity of the cache
java.lang.IllegalArgumentException
- when the capacity is smaller or equal to zeroMethod Detail |
---|
public V put(K key, V value)
put
in interface Cache<K,V>
key
- key to add to the cachevalue
- value to map the key on
public V get(K key)
get
in interface Cache<K,V>
key
- key to get the value for
public V remove(K key)
remove
in interface Cache<K,V>
key
- key to remove from the cache.
public V update(K key, V value)
update
in interface Cache<K,V>
key
- key to change the value forvalue
- new value associated with the key
public abstract boolean containsKey(K key)
Cache
containsKey
in interface Cache<K,V>
key
- key to check
public abstract int size()
Cache
size
in interface Cache<K,V>
public abstract K nextEvicted()
Cache
nextEvicted
in interface Cache<K,V>
public abstract void evict()
Cache
evict
in interface Cache<K,V>
public abstract java.lang.String toString()
toString
in class java.lang.Object
public float hitRatio()
hitRatio
in interface Cache<K,V>
public long hits()
hits
in interface Cache<K,V>
public long misses()
misses
in interface Cache<K,V>
public long requests()
requests
in interface Cache<K,V>
public int capacity()
capacity
in interface Cache<K,V>
public void resetCounters()
resetCounters
in interface Cache<K,V>
public Resolver<K,V> getResolver()
getResolver
in interface Cache<K,V>
public Resolver<K,V> setResolver(Resolver<K,V> resolver)
setResolver
in interface Cache<K,V>
resolver
- new resolver we want to associate with this cache.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |