K
- The keyV
- The valueK
- The keyV
- The valuepublic class LRUCache<K,V> extends java.lang.Object implements Cache<K,V>
Modifier and Type | Class and Description |
---|---|
class |
LRUCache.LRUCacheEntry<K,V>
Double linked cell used as entry in the cache list.
|
class |
LRUCache.LRUList
Double queued list used to store cache entries.
|
Constructor and Description |
---|
LRUCache(int max)
Creates a LRU cache
|
Modifier and Type | Method and Description |
---|---|
void |
flush()
Flushes the cached objects from the cache.
|
V |
get(K key)
Returns the object paired with the specified key if it's
present in the cache, otherwise must return null.
|
void |
insert(K key,
V o)
Inserts the specified object into the cache following the
implemented policy.
|
V |
peek(K key)
Returns the object paired with the specified key if it's
present in the cache, otherwise must return null.
|
void |
remove(K key)
Remove the cached object paired with the specified key.
|
void |
setListener(CacheListener listener)
Set the cache listener
|
int |
size()
The cache size
|
public LRUCache(int max)
max
- The maximum number of entriespublic V get(K key)
Cache.peek(K)
this method not only return whether
the object is present in the cache or not, but also
applies the implemented policy that will "refresh" the cached
object in the cache, because this cached object
was really requested.get
in interface Cache<K,V>
key
- the key paired with the objectCache.peek(K)
public V peek(K key)
Cache.get(K)
.peek
in interface Cache<K,V>
key
- the key paired with the objectCache.get(K)
public void insert(K key, V o)
insert
in interface Cache<K,V>
key
- the key paired with the objecto
- the object to cacheCache.remove(K)
public void remove(K key)
remove
in interface Cache<K,V>
key
- the key paired with the objectCache.insert(K, V)
public void flush()
public int size()
public void setListener(CacheListener listener)
setListener
in interface Cache<K,V>
listener
- The listenerCopyright © 2013 IronJacamar (http://www.ironjacamar.org)