Package org.postgresql.util
Class LruCache<Key,Value extends CanEstimateSize>
- java.lang.Object
-
- org.postgresql.util.LruCache<Key,Value>
-
public class LruCache<Key,Value extends CanEstimateSize> extends java.lang.Object
Caches values in simple least-recently-accessed order.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LruCache.CreateAction<Key,Value>
When the entry is not present in cache, this create action is used to create one.static interface
LruCache.EvictAction<Value>
Action that is invoked when the entry is removed from the cache.
-
Field Summary
Fields Modifier and Type Field Description static LruCache.CreateAction
NOOP_CREATE_ACTION
static LruCache.EvictAction
NOOP_EVICT_ACTION
-
Constructor Summary
Constructors Constructor Description LruCache(int maxSizeEntries, long maxSizeBytes, boolean accessOrder)
LruCache(int maxSizeEntries, long maxSizeBytes, boolean accessOrder, LruCache.CreateAction<Key,Value> createAction, LruCache.EvictAction<Value> onEvict)
-
-
-
Field Detail
-
NOOP_CREATE_ACTION
public static final LruCache.CreateAction NOOP_CREATE_ACTION
-
NOOP_EVICT_ACTION
public static final LruCache.EvictAction NOOP_EVICT_ACTION
-
-
Constructor Detail
-
LruCache
public LruCache(int maxSizeEntries, long maxSizeBytes, boolean accessOrder)
-
LruCache
public LruCache(int maxSizeEntries, long maxSizeBytes, boolean accessOrder, LruCache.CreateAction<Key,Value> createAction, LruCache.EvictAction<Value> onEvict)
-
-
Method Detail
-
get
public Value get(Key key)
Returns an entry from the cache.- Parameters:
key
- cache key- Returns:
- entry from cache or null if cache does not contain given key.
-
borrow
public Value borrow(Key key) throws java.sql.SQLException
Borrows an entry from the cache.- Parameters:
key
- cache key- Returns:
- entry from cache or newly created entry if cache does not contain given key.
- Throws:
java.sql.SQLException
- if entry creation fails
-
-