Class ThreadLocalIdentityCache<K,​V>


  • final class ThreadLocalIdentityCache<K,​V>
    extends Cache<K,​V>
    • Field Detail

      • _parent

        private final Cache<K,​V> _parent
      • _threadCaches

        private final java.lang.ThreadLocal<SatelliteCache<K,​V>> _threadCaches
    • Constructor Detail

      • ThreadLocalIdentityCache

        public ThreadLocalIdentityCache()
      • ThreadLocalIdentityCache

        public ThreadLocalIdentityCache​(Cache<K,​V> parent)
    • Method Detail

      • getSatelliteCache

        public Cache<K,​V> getSatelliteCache()
        Description copied from class: Cache
        Returns a thread-specific satellite cache chained to this cache. If the target cache is already a satellite cache, it will simply return itself. Note that the returned cache is completely unsynchronized and is not safe for concurrent access.
        Specified by:
        getSatelliteCache in class Cache<K,​V>
        Returns:
        A thread-specific satellite cache.
      • replace

        public boolean replace​(K key,
                               V expectedValue,
                               V updatedValue)
        Description copied from class: Cache

        Replaces the value associated with a given key if the current value matches the expected value.

        Note that the replaced value will not be propagated to child caches that already have a value for the same key. As such, this method is of limited usefulness and should only be called on isolated Level 1 caches.

        Specified by:
        replace in class Cache<K,​V>
        Parameters:
        key - The key for which to change the associated value.
        expectedValue - The expected value to be replaced.
        updatedValue - The new value.
        Returns:
        true if the expected value was replaced; otherwise, false.
      • cache

        public V cache​(K key,
                       V value)
        Description copied from class: Cache
        Places a value in the cache only if no value exists with the same key.
        Specified by:
        cache in class Cache<K,​V>
        Parameters:
        key - The key associated with the given value.
        value - The value to insert into the cache.
        Returns:
        The cached value associated with the given key, which will be the provided value if no existing value was found.
      • get

        public V get​(K key)
        Description copied from class: Cache
        Gets the value associated with the given key.
        Specified by:
        get in class Cache<K,​V>
        Parameters:
        key - The key associated with the desired value.
        Returns:
        The value corresponding the given key, or null if no value was found.