Package io.grpc.rls

Interface LruCache<K,V>

All Known Implementing Classes:
CachingRlsLbClient.RlsAsyncLruCache, LinkedHashLruCache

interface LruCache<K,V>
An LruCache is a cache with least recently used eviction.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A Listener notifies cache eviction events.
    static enum 
    Type of cache eviction.
  • Method Summary

    Modifier and Type
    Method
    Description
    cache(K key, V value)
    Populates a cache entry.
    void
    Closes underlying resources.
    int
    Returns the estimated number of entry of the cache.
    boolean
    Returns true if given key is cached.
    Invalidates an entry for given key if exists.
    void
    Invalidates cache entries for all keys.
    read(K key)
    Returns cached value for given key if exists, otherwise null.
  • Method Details

    • cache

      @Nullable V cache(K key, V value)
      Populates a cache entry. If the cache entry for given key already exists, the value will be replaced to the new value.
      Returns:
      the previous value associated with key, otherwise null
    • read

      Returns cached value for given key if exists, otherwise null. This operation doesn't return already expired cache entry.
    • invalidate

      @Nullable V invalidate(K key)
      Invalidates an entry for given key if exists. This operation will trigger LruCache.EvictionListener with LruCache.EvictionType.EXPLICIT.
      Returns:
      the previous value associated with key, otherwise null
    • invalidateAll

      void invalidateAll()
      Invalidates cache entries for all keys. This operation will trigger LruCache.EvictionListener with LruCache.EvictionType.EXPLICIT.
    • hasCacheEntry

      @CheckReturnValue boolean hasCacheEntry(K key)
      Returns true if given key is cached.
    • estimatedSize

      @CheckReturnValue int estimatedSize()
      Returns the estimated number of entry of the cache. Note that the size can be larger than its true size, because there might be already expired cache.
    • close

      void close()
      Closes underlying resources.