Interface CacheMap<T>
- All Known Implementing Classes:
HazelcastMapAdapter,InMemoryCacheMap,MVStoreCacheMap
public interface CacheMap<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAttempts made by the defaultupdate(java.lang.String, com.norconex.crawler.core.cluster.CacheEntryUpdate<T>)before giving up. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()computeIfAbsent(String key, Function<String, ? extends T> mappingFunction) computeIfPresent(String key, BiFunction<String, ? super T, ? extends T> remappingFunction) booleancontainsKey(String key) longcount(QueryFilter filter) Counts the number of entries matching the given query filter.voiddelete(QueryFilter filter) Deletes entries matching the given query filter.voidforEach(BiConsumer<String, ? super T> action) default voidforEachMatching(QueryFilter filter, Consumer<? super T> action) Visits matching entries synchronously.getName()Gets the name of this cache.getOrDefault(String key, T defaultValue) booleanisEmpty()booleanReturns whether this cache persists data across restarts.keys()Returns all keys in this cache.default voidloadAll()Eagerly loads all entries from the backing store (e.g., JDBC) into this cache.voidvoidputIfAbsent(String key, T value) If the specified key is not already associated with a value, associates it with the given value.query(QueryFilter filter) Queries the cache for entries matching the given query filter.queryIterator(QueryFilter filter) Queries the cache for entries matching the given filter and returns an iterator.voidbooleanlongsize()Counts the number of entries in this cache.update(String key, CacheEntryUpdate<T> update) Atomically changes an entry as the given update decides from its current value.updateAll(Collection<String> keys, CacheEntryUpdate<T> update) Atomically changes each of the given entries as the given update decides from its current value, the wayupdate(String, CacheEntryUpdate)does for one.
-
Field Details
-
DEFAULT_UPDATE_MAX_ATTEMPTS
static final int DEFAULT_UPDATE_MAX_ATTEMPTSAttempts made by the defaultupdate(java.lang.String, com.norconex.crawler.core.cluster.CacheEntryUpdate<T>)before giving up.- See Also:
-
-
Method Details
-
isEmpty
boolean isEmpty() -
put
-
putAll
-
get
-
remove
-
clear
void clear() -
computeIfAbsent
-
computeIfPresent
-
compute
-
merge
-
containsKey
-
getOrDefault
-
putIfAbsent
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 associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key.
-
replace
-
update
Atomically changes an entry as the given update decides from its current value. Unlikereplace(String, Object, Object), nothing is compared with an expected value, so the outcome does not depend on how the cache stores or serializes values. SeeCacheEntryUpdatefor 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 keyupdate- decides the entry's new value- Returns:
- the new value, or empty if the update left the entry unchanged
-
updateAll
Atomically changes each of the given entries as the given update decides from its current value, the wayupdate(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
Queries the cache for entries matching the given query filter. Note: This method loads all results into memory at once. For large result sets, preferforEachMatching(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
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
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 filteraction- the action to perform for each matching entry
-
count
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
Deletes entries matching the given query filter.- Parameters:
filter- the query filter
-
forEach
-
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 withLAZYinitial load mode, this ensures subÂsequentsize(),forEach(java.util.function.BiConsumer<java.lang.String, ? super T>), andkeys()calls return correct results. If the cache already has its data loaded (e.g.,EAGERmode), 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
-