E
- the type of element that this cache holds.public final class LongLruCache<E>
extends java.lang.Object
implements java.lang.AutoCloseable, java.io.Serializable
When an element is evicted it is closed by calling the closer function with the element as an argument.
When a new key arrives the factory function is called in order to create the new element associated with that key.
Constructor and Description |
---|
LongLruCache(int capacity,
java.util.function.LongFunction<E> factory,
java.util.function.Consumer<E> closer)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
capacity() |
void |
close() |
E |
lookup(long key)
Looks up an element in the cache, creating a new element if it doesn't exist and evicting the least recently used
element if there's no space left in the cache.
|
public LongLruCache(int capacity, java.util.function.LongFunction<E> factory, java.util.function.Consumer<E> closer)
capacity
- this is the fixed capacity of the cache.factory
- a function for constructing new elements based upon keys.closer
- a function for cleaning up resources associated with elements.public E lookup(long key)
key
- the key to lookup the element by.public int capacity()
public void close()
close
in interface java.lang.AutoCloseable
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.