Interface CacheMap<T>
- All Known Implementing Classes:
HazelcastMapAdapter,InMemoryCacheMap,MVStoreCacheMap
public interface CacheMap<T>
-
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) 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 for memory-efficient processing of results.voidbooleanlongsize()Counts the number of entries in this cache.
-
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
-
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, consider usingqueryIterator(com.norconex.crawler.core.cluster.QueryFilter)instead.- 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 for memory-efficient processing of results. This avoids loading all results into memory at once.- Parameters:
filter- the query filter- Returns:
- an iterator over the matching entries
-
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
-