Interface BasicCache<K,​V>

  • All Superinterfaces:
    AsyncCache<K,​V>, java.util.concurrent.ConcurrentMap<K,​V>, Lifecycle, java.util.Map<K,​V>
    All Known Subinterfaces:
    AdvancedCache<K,​V>, Cache<K,​V>, RemoteCache<K,​V>, SecureCache<K,​V>
    All Known Implementing Classes:
    AbstractDelegatingAdvancedCache, org.infinispan.cache.impl.AbstractDelegatingAdvancedCache, AbstractDelegatingCache, org.infinispan.cache.impl.AbstractDelegatingCache

    public interface BasicCache<K,​V>
    extends AsyncCache<K,​V>, java.util.concurrent.ConcurrentMap<K,​V>, Lifecycle
    BasicCache provides the common building block for the two different types of caches that Infinispan provides: embedded and remote.

    For convenience, BasicCache extends ConcurrentMap and implements all methods accordingly, although methods like Map.keySet(), Map.values() and Map.entrySet() are expensive (prohibitively so when using a distributed cache) and frequent use of these methods is not recommended.

    Other methods such as Map.size() provide an approximation-only, and should not be relied on for an accurate picture as to the size of the entire, distributed cache. Remote nodes are not queried and in-fly transactions are not taken into account, even if Map.size() is invoked from within such a transaction.

    Also, like many ConcurrentMap implementations, BasicCache does not support the use of null keys or values.

    Unsupported operations

    Map.containsValue(Object)

    Please see the Infinispan documentation and/or the 5 Minute Usage Tutorial for more details.

    Since:
    5.1
    Author:
    Mircea.Markus@jboss.com, Manik Surtani, Galder ZamarreƱo, Tristan Tarrant
    See Also:
    Infinispan documentation, 5 Minute Usage Tutorial
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      V compute​(K key, java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
      An overloaded form of ConcurrentMap.compute(Object, BiFunction) which takes in lifespan parameters.
      V compute​(K key, java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of ConcurrentMap.compute(Object, BiFunction) which takes in lifespan and maxIdleTime parameters.
      V computeIfAbsent​(K key, java.util.function.Function<? super K,​? extends V> mappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
      An overloaded form of ConcurrentMap.computeIfAbsent(Object, Function) which takes in lifespan parameters.
      V computeIfAbsent​(K key, java.util.function.Function<? super K,​? extends V> mappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of ConcurrentMap.computeIfAbsent(Object, Function) which takes in lifespan and maxIdleTime parameters.
      V computeIfPresent​(K key, java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
      An overloaded form of ConcurrentMap.computeIfPresent(Object, BiFunction) which takes in lifespan parameters.
      V computeIfPresent​(K key, java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of ConcurrentMap.computeIfPresent(Object, BiFunction) which takes in lifespan and maxIdleTime parameters.
      java.lang.String getName()
      Retrieves the name of the cache
      java.lang.String getVersion()
      Retrieves the version of Infinispan
      V merge​(K key, V value, java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit)
      An overloaded form of ConcurrentMap.merge(Object, Object, BiFunction) which takes in lifespan parameters.
      V merge​(K key, V value, java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of ConcurrentMap.merge(Object, Object, BiFunction) which takes in lifespan parameters.
      V put​(K key, V value)
      If the return value of this operation will be ignored by the application, the user is strongly encouraged to use the Flag.IGNORE_RETURN_VALUES flag when invoking this method in order to make it behave as efficiently as possible (i.e.
      V put​(K key, V value, long lifespan, java.util.concurrent.TimeUnit unit)
      An overloaded form of put(Object, Object), which takes in lifespan parameters.
      V put​(K key, V value, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of put(Object, Object), which takes in lifespan parameters.
      void putAll​(java.util.Map<? extends K,​? extends V> map, long lifespan, java.util.concurrent.TimeUnit unit)
      An overloaded form of Map.putAll(Map), which takes in lifespan parameters.
      void putAll​(java.util.Map<? extends K,​? extends V> map, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of Map.putAll(Map), which takes in lifespan parameters.
      V putIfAbsent​(K key, V value, long lifespan, java.util.concurrent.TimeUnit unit)
      An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
      V putIfAbsent​(K key, V value, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
      V remove​(java.lang.Object key)
      If the return value of this operation will be ignored by the application, the user is strongly encouraged to use the Flag.IGNORE_RETURN_VALUES flag when invoking this method in order to make it behave as efficiently as possible (i.e.
      V replace​(K key, V value, long lifespan, java.util.concurrent.TimeUnit unit)
      An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
      V replace​(K key, V value, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
      boolean replace​(K key, V oldValue, V value, long lifespan, java.util.concurrent.TimeUnit unit)
      An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.
      boolean replace​(K key, V oldValue, V value, long lifespan, java.util.concurrent.TimeUnit lifespanUnit, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleTimeUnit)
      An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.
      • Methods inherited from interface java.util.concurrent.ConcurrentMap

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
      • Methods inherited from interface java.util.Map

        clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, size, values
    • Method Detail

      • getName

        java.lang.String getName()
        Retrieves the name of the cache
        Returns:
        the name of the cache
      • getVersion

        java.lang.String getVersion()
        Retrieves the version of Infinispan
        Returns:
        a version string
      • put

        V put​(K key,
              V value)
        If the return value of this operation will be ignored by the application, the user is strongly encouraged to use the Flag.IGNORE_RETURN_VALUES flag when invoking this method in order to make it behave as efficiently as possible (i.e. avoiding needless remote or network calls).
        Specified by:
        put in interface java.util.Map<K,​V>
      • put

        V put​(K key,
              V value,
              long lifespan,
              java.util.concurrent.TimeUnit unit)
        An overloaded form of put(Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        unit - unit of measurement for the lifespan
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • putIfAbsent

        V putIfAbsent​(K key,
                      V value,
                      long lifespan,
                      java.util.concurrent.TimeUnit unit)
        An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        unit - unit of measurement for the lifespan
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • putAll

        void putAll​(java.util.Map<? extends K,​? extends V> map,
                    long lifespan,
                    java.util.concurrent.TimeUnit unit)
        An overloaded form of Map.putAll(Map), which takes in lifespan parameters. Note that the lifespan is applied to all mappings in the map passed in.
        Parameters:
        map - map containing mappings to enter
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        unit - unit of measurement for the lifespan
      • replace

        V replace​(K key,
                  V value,
                  long lifespan,
                  java.util.concurrent.TimeUnit unit)
        An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        unit - unit of measurement for the lifespan
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • replace

        boolean replace​(K key,
                        V oldValue,
                        V value,
                        long lifespan,
                        java.util.concurrent.TimeUnit unit)
        An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        oldValue - value to replace
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        unit - unit of measurement for the lifespan
        Returns:
        true if the value was replaced, false otherwise
      • put

        V put​(K key,
              V value,
              long lifespan,
              java.util.concurrent.TimeUnit lifespanUnit,
              long maxIdleTime,
              java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of put(Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • putIfAbsent

        V putIfAbsent​(K key,
                      V value,
                      long lifespan,
                      java.util.concurrent.TimeUnit lifespanUnit,
                      long maxIdleTime,
                      java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of ConcurrentMap.putIfAbsent(Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • putAll

        void putAll​(java.util.Map<? extends K,​? extends V> map,
                    long lifespan,
                    java.util.concurrent.TimeUnit lifespanUnit,
                    long maxIdleTime,
                    java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of Map.putAll(Map), which takes in lifespan parameters. Note that the lifespan is applied to all mappings in the map passed in.
        Parameters:
        map - map containing mappings to enter
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
      • replace

        V replace​(K key,
                  V value,
                  long lifespan,
                  java.util.concurrent.TimeUnit lifespanUnit,
                  long maxIdleTime,
                  java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of ConcurrentMap.replace(Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the value being replaced, or null if nothing is being replaced.
      • replace

        boolean replace​(K key,
                        V oldValue,
                        V value,
                        long lifespan,
                        java.util.concurrent.TimeUnit lifespanUnit,
                        long maxIdleTime,
                        java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of ConcurrentMap.replace(Object, Object, Object), which takes in lifespan parameters.
        Parameters:
        key - key to use
        oldValue - value to replace
        value - value to store
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        true if the value was replaced, false otherwise
      • merge

        V merge​(K key,
                V value,
                java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction,
                long lifespan,
                java.util.concurrent.TimeUnit lifespanUnit)
        An overloaded form of ConcurrentMap.merge(Object, Object, BiFunction) which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - new value to merge with existing value
        remappingFunction - function to use to merge new and existing values into a merged value to store under key
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        Returns:
        the merged value that was stored under key
      • merge

        V merge​(K key,
                V value,
                java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction,
                long lifespan,
                java.util.concurrent.TimeUnit lifespanUnit,
                long maxIdleTime,
                java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of ConcurrentMap.merge(Object, Object, BiFunction) which takes in lifespan parameters.
        Parameters:
        key - key to use
        value - new value to merge with existing value
        remappingFunction - function to use to merge new and existing values into a merged value to store under key
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the merged value that was stored under key
      • compute

        V compute​(K key,
                  java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction,
                  long lifespan,
                  java.util.concurrent.TimeUnit lifespanUnit)
        An overloaded form of ConcurrentMap.compute(Object, BiFunction) which takes in lifespan parameters.
        Parameters:
        key - key to use
        remappingFunction - function to use to compute and store the value under key
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        Returns:
        the computed value that was stored under key
      • compute

        V compute​(K key,
                  java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction,
                  long lifespan,
                  java.util.concurrent.TimeUnit lifespanUnit,
                  long maxIdleTime,
                  java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of ConcurrentMap.compute(Object, BiFunction) which takes in lifespan and maxIdleTime parameters.
        Parameters:
        key - key to use
        remappingFunction - function to use to compute and store the value under key
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the computed value that was stored under key
      • computeIfPresent

        V computeIfPresent​(K key,
                           java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction,
                           long lifespan,
                           java.util.concurrent.TimeUnit lifespanUnit)
        An overloaded form of ConcurrentMap.computeIfPresent(Object, BiFunction) which takes in lifespan parameters.
        Parameters:
        key - key to use
        remappingFunction - function to use to compute and store the value under key, if such exists
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        Returns:
        the computed value that was stored under key
      • computeIfPresent

        V computeIfPresent​(K key,
                           java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction,
                           long lifespan,
                           java.util.concurrent.TimeUnit lifespanUnit,
                           long maxIdleTime,
                           java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of ConcurrentMap.computeIfPresent(Object, BiFunction) which takes in lifespan and maxIdleTime parameters.
        Parameters:
        key - key to use
        remappingFunction - function to use to compute and store the value under key, if such exists
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the computed value that was stored under key
      • computeIfAbsent

        V computeIfAbsent​(K key,
                          java.util.function.Function<? super K,​? extends V> mappingFunction,
                          long lifespan,
                          java.util.concurrent.TimeUnit lifespanUnit)
        An overloaded form of ConcurrentMap.computeIfAbsent(Object, Function) which takes in lifespan parameters.
        Parameters:
        key - key to use
        mappingFunction - function to use to compute and store the value under key, if the key is absent
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        Returns:
        the computed value that was stored under key
      • computeIfAbsent

        V computeIfAbsent​(K key,
                          java.util.function.Function<? super K,​? extends V> mappingFunction,
                          long lifespan,
                          java.util.concurrent.TimeUnit lifespanUnit,
                          long maxIdleTime,
                          java.util.concurrent.TimeUnit maxIdleTimeUnit)
        An overloaded form of ConcurrentMap.computeIfAbsent(Object, Function) which takes in lifespan and maxIdleTime parameters.
        Parameters:
        key - key to use
        mappingFunction - function to use to compute and store the value under key, if the key is absent
        lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
        lifespanUnit - time unit for lifespan
        maxIdleTime - the maximum amount of time this key is allowed to be idle for before it is considered as expired
        maxIdleTimeUnit - time unit for max idle time
        Returns:
        the computed value that was stored under key
      • remove

        V remove​(java.lang.Object key)
        If the return value of this operation will be ignored by the application, the user is strongly encouraged to use the Flag.IGNORE_RETURN_VALUES flag when invoking this method in order to make it behave as efficiently as possible (i.e. avoiding needless remote or network calls).
        Specified by:
        remove in interface java.util.Map<K,​V>