Class LruCache<Key,Value extends CanEstimateSize>

java.lang.Object
org.postgresql.util.LruCache<Key,Value>
All Implemented Interfaces:
Gettable<Key,Value>

public class LruCache<Key,Value extends CanEstimateSize> extends Object implements Gettable<Key,Value>
Caches values in simple least-recently-accessed order.
  • Constructor Details

    • LruCache

      public LruCache(int maxSizeEntries, long maxSizeBytes, boolean accessOrder)
    • LruCache

      public LruCache(int maxSizeEntries, long maxSizeBytes, boolean accessOrder, @Nullable LruCache.CreateAction<Key,Value> createAction, @Nullable LruCache.EvictAction<Value> onEvict)
  • Method Details

    • get

      public @Nullable Value get(Key key)
      Returns an entry from the cache.
      Specified by:
      get in interface Gettable<Key,Value extends CanEstimateSize>
      Parameters:
      key - cache key
      Returns:
      entry from cache or null if cache does not contain given key.
    • borrow

      public Value borrow(Key key) throws 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:
      SQLException - if entry creation fails
    • put

      public void put(Key key, Value value)
      Returns given value to the cache.
      Parameters:
      key - key
      value - value
    • putAll

      public void putAll(Map<Key,Value> m)
      Puts all the values from the given map into the cache.
      Parameters:
      m - The map containing entries to put into the cache