|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.neo4j.kernel.impl.cache.LruCache<K,E>
public class LruCache<K,E>
Simple implementation of Least-recently-used cache.
The cache has a maxSize set and when the number of cached
elements exceeds that limit the least recently used element will be removed.
| Constructor Summary | |
|---|---|
LruCache(String name,
int maxSize,
AdaptiveCacheManager cacheManager)
Creates a LRU cache. |
|
| Method Summary | |
|---|---|
void |
clear()
Removing all cached elements. |
void |
elementCleaned(E element)
|
E |
get(K key)
Returns the cached element for key. |
String |
getName()
Returns the name of the cache. |
long |
hitCount()
|
boolean |
isAdaptive()
|
int |
maxSize()
Returns the maximum size of this cache. |
long |
missCount()
|
void |
put(K key,
E element)
Adds element to cache. |
void |
putAll(Map<K,E> map)
|
E |
remove(K key)
Removes the element for key from cache and returns it. |
void |
resize(int newMaxSize)
Changes the max size of the cache. |
void |
setAdaptiveStatus(boolean status)
|
int |
size()
Returns the cache size. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LruCache(String name,
int maxSize,
AdaptiveCacheManager cacheManager)
maxSize < 1 an
IllegalArgumentException is thrown.
name - name of cachemaxSize - maximum size of this cachecacheManager - adaptive cache manager or null if adaptive caching not needed| Method Detail |
|---|
public String getName()
Cache
getName in interface Cache<K,E>
public void put(K key,
E element)
Cacheelement to cache.
put in interface Cache<K,E>key - the key for the elementpublic E remove(K key)
Cachekey from cache and returns it. If
the no element for key exists null is
returned.
remove in interface Cache<K,E>key - the key for the element
null if element didn't
existpublic E get(K key)
Cachekey. If the element isn't
in cache null is returned.
get in interface Cache<K,E>key - the key for the element
null if element didn't existpublic void clear()
Cache
clear in interface Cache<K,E>public int size()
Cache
size in interface Cache<K,E>public int maxSize()
maxSize in interface Cache<K,E>public void resize(int newMaxSize)
newMaxSize is
greater then maxSize() next invoke to maxSize()
will return newMaxSize and the entries in cache will not
be modified.
If newMaxSize is less then size()
the cache will shrink itself removing least recently used element until
size() equals newMaxSize. For each element
removed the elementCleaned(E) method is invoked.
If newMaxSize is less then 1 an
IllegalArgumentException is thrown.
resize in interface Cache<K,E>newMaxSize - the new maximum size of the cachepublic void elementCleaned(E element)
elementCleaned in interface Cache<K,E>public boolean isAdaptive()
isAdaptive in interface Cache<K,E>public void setAdaptiveStatus(boolean status)
setAdaptiveStatus in interface Cache<K,E>public void putAll(Map<K,E> map)
putAll in interface Cache<K,E>public long hitCount()
hitCount in interface Cache<K,E>public long missCount()
missCount in interface Cache<K,E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||