Interface BasicCache<K,V>

All Superinterfaces:
AsyncCache<K,V>, ConcurrentMap<K,V>, Lifecycle, Map<K,V>

public interface BasicCache<K,V> extends AsyncCache<K,V>, 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:
[email protected], Manik Surtani, Galder ZamarreƱo, Tristan Tarrant
See Also:
  • Method Details

    • getName

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

      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 org.infinispan.context.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 Map<K,V>
    • put

      V put(K key, V value, long lifespan, 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, 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(Map<? extends K,? extends V> map, long lifespan, 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, 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, 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, TimeUnit lifespanUnit, long maxIdleTime, 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, TimeUnit lifespanUnit, long maxIdleTime, 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(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, 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, TimeUnit lifespanUnit, long maxIdleTime, 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, TimeUnit lifespanUnit, long maxIdleTime, 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, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, 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, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, 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, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, 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, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, 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, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, 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, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, 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, Function<? super K,? extends V> mappingFunction, long lifespan, 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, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, 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(Object key)
      If the return value of this operation will be ignored by the application, the user is strongly encouraged to use the org.infinispan.context.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 Map<K,V>