Interface CacheAccessor<K,​V>

  • Type Parameters:
    K - Key type.
    V - Value type.

    public interface CacheAccessor<K,​V>
    Interface defining access to the client-side cache. The cache must support value retrieval, value update (for Redis Cache read-through so values obtained from Redis get written into the client-side cache) and removal (used for invalidations).
    Since:
    6.0
    Author:
    Mark Paluch
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void evict​(K key)
      Evict the mapping for this key from this cache if it is present.
      static <K,​V>
      CacheAccessor<K,​V>
      forMap​(Map<K,​V> map)
      Obtain a CacheAccessor for a cache object implementing Map.
      V get​(K key)
      Return the value to which this cache maps the specified key.
      void put​(K key, V value)
      Associate the specified value with the specified key in this cache.
    • Method Detail

      • forMap

        static <K,​V> CacheAccessor<K,​V> forMap​(Map<K,​V> map)
        Obtain a CacheAccessor for a cache object implementing Map.
        Type Parameters:
        K - Key type.
        V - Value type.
        Parameters:
        map - the cache.
        Returns:
        a CacheAccessor backed by a Map implementation.
      • get

        V get​(K key)
        Return the value to which this cache maps the specified key.

        Note: This method does not allow for differentiating between a cached null value and no cache entry found at all.

        Parameters:
        key - the key whose associated value is to be returned.
        Returns:
        the value to which this cache maps the specified key (which may be null itself), or also null if the cache contains no mapping for this key.
      • put

        void put​(K key,
                 V value)
        Associate the specified value with the specified key in this cache.

        If the cache previously contained a mapping for this key, the old value is replaced by the specified value.

        Actual registration may be performed in an asynchronous or deferred fashion, with subsequent lookups possibly not seeing the entry yet. This may for example be the case with transactional cache decorators.

        Parameters:
        key - the key with which the specified value is to be associated.
        value - the value to be associated with the specified key.
      • evict

        void evict​(K key)
        Evict the mapping for this key from this cache if it is present.

        Actual eviction may be performed in an asynchronous or deferred fashion, with subsequent lookups possibly still seeing the entry.

        Parameters:
        key - the key whose mapping is to be removed from the cache.