Interface CacheMap<T>

All Known Implementing Classes:
HazelcastMapAdapter, InMemoryCacheMap, MVStoreCacheMap

public interface CacheMap<T>
  • Field Details

  • Method Details

    • isEmpty

      boolean isEmpty()
    • put

      void put(String key, T value)
    • putAll

      void putAll(Map<String,T> entries)
    • get

      Optional<T> get(String key)
    • remove

      void remove(String key)
    • clear

      void clear()
    • computeIfAbsent

      T computeIfAbsent(String key, Function<String,? extends T> mappingFunction)
    • computeIfPresent

      Optional<T> computeIfPresent(String key, BiFunction<String,? super T,? extends T> remappingFunction)
    • compute

      Optional<T> compute(String key, BiFunction<String,? super T,? extends T> remappingFunction)
    • merge

      T merge(String key, T value, BiFunction<? super T,? super T,? extends T> remappingFunction)
    • containsKey

      boolean containsKey(String key)
    • getOrDefault

      T getOrDefault(String key, T defaultValue)
    • putIfAbsent

      T putIfAbsent(String key, T value)
      If the specified key is not already associated with a value, associates it with the given value. This is equivalent to, for this cache:
       if (!cache.containsKey(key))
           return map.put(key, value);
       else
           return map.get(key);
      
      except that the action is performed atomically.
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key.
    • replace

      boolean replace(String key, T oldValue, T newValue)
    • update

      default Optional<T> update(String key, CacheEntryUpdate<T> update)
      Atomically changes an entry as the given update decides from its current value. Unlike replace(String, Object, Object), nothing is compared with an expected value, so the outcome does not depend on how the cache stores or serializes values. See CacheEntryUpdate for what an update may do.

      This default implementation retries a compare-and-set until it succeeds; implementations should override it with an atomic operation of their own.

      Parameters:
      key - the entry key
      update - decides the entry's new value
      Returns:
      the new value, or empty if the update left the entry unchanged
    • updateAll

      default Map<String,T> updateAll(Collection<String> keys, CacheEntryUpdate<T> update)
      Atomically changes each of the given entries as the given update decides from its current value, the way update(String, CacheEntryUpdate) does for one. Each entry is changed atomically on its own; the batch as a whole is not a transaction. Implementations may do it in fewer round trips than one per key.
      Parameters:
      keys - the entry keys (duplicates are updated once)
      update - decides each entry's new value
      Returns:
      the new values of the entries that were changed, by key, in the order of the given keys
    • query

      List<T> query(QueryFilter filter)
      Queries the cache for entries matching the given query filter. Note: This method loads all results into memory at once. For large result sets, prefer forEachMatching(com.norconex.crawler.core.cluster.QueryFilter, java.util.function.Consumer<? super T>).
      Parameters:
      filter - the query filter
      Returns:
      a list of matching entries or an empty list (never null)
    • queryIterator

      Iterator<T> queryIterator(QueryFilter filter)
      Queries the cache for entries matching the given filter and returns an iterator. Whether results are loaded eagerly depends on the cache implementation.
      Parameters:
      filter - the query filter
      Returns:
      an iterator over the matching entries
    • forEachMatching

      default void forEachMatching(QueryFilter filter, Consumer<? super T> action)
      Visits matching entries synchronously. Implementations may override this method to stream results while keeping traversal resources scoped to the call. The consumer should not mutate the cache during traversal.
      Parameters:
      filter - the query filter
      action - the action to perform for each matching entry
    • count

      long count(QueryFilter filter)
      Counts the number of entries matching the given query filter.
      Parameters:
      filter - the query filter
      Returns:
      the count of matching entries
    • size

      long size()
      Counts the number of entries in this cache.
      Returns:
      the number of entries
    • delete

      void delete(QueryFilter filter)
      Deletes entries matching the given query filter.
      Parameters:
      filter - the query filter
    • forEach

      void forEach(BiConsumer<String,? super T> action)
    • keys

      List<String> keys()
      Returns all keys in this cache. For distributed caches, this includes keys from all nodes in the cluster, not just locally-owned keys.
      Returns:
      a list of all keys in the cache
    • loadAll

      default void loadAll()
      Eagerly loads all entries from the backing store (e.g., JDBC) into this cache. For caches configured with LAZY initial load mode, this ensures sub­sequent size(), forEach(java.util.function.BiConsumer<java.lang.String, ? super T>), and keys() calls return correct results. If the cache already has its data loaded (e.g., EAGER mode), this is a no-op.
    • isPersistent

      boolean isPersistent()
      Returns whether this cache persists data across restarts.
      Returns:
      true if the cache is persistent, false if ephemeral
    • getName

      String getName()
      Gets the name of this cache.
      Returns:
      cache name