Package com.hazelcast.map
Interface QueryCache<K,V>
- Type Parameters:
K
- the type of key for thisQueryCache
V
- the type of value for thisQueryCache
public interface QueryCache<K,V>
A concurrent, queryable data structure which is used to cache results of
a continuous query executed on an
IMap
. It can be also thought
of as an always up to date view or snapshot of the IMap
.
Typically, QueryCache
is used for performance reasons.
This QueryCache
can be configured via QueryCacheConfig
.
It can be reached like this:
IMap map = hzInstance.getMap("mapName");
Predicate predicate = TruePredicate.INSTANCE;
QueryCache cache = map.getQueryCache(cacheId, predicate, includeValue);
This cache is evictable. The eviction can be configured with QueryCacheConfig.setEvictionConfig(com.hazelcast.config.EvictionConfig)
.
Events caused by IMap
eviction are not reflected to this cache.
But the events published after an explicit call to IMap.evict(K)
are reflected to this cache.
GOTCHAS
-
This
QueryCache
implementation relies on the eventing system, if a listener is attached to thisQueryCache
it may receive same event more than once in case of a system failure. Check outtryRecover()
-
All writes to this
QueryCache
is reflected to underlyingIMap
and that write operation will eventually be reflected to thisQueryCache
after receiving the event of that operation. -
Currently, updates performed on the entries are reflected in the indexes
in a non-atomic way. Therefore, if there are indexes configured for the
query cache, their state may slightly lag behind the state of the
entries. Use map listeners if you need to observe the state when the
entry store and its indexes are consistent about the state of a
particular entry, see
addEntryListener
for more details. -
There are some gotchas same with underlying
IMap
implementation, one should take care of them before using thisQueryCache
. Please check gotchas section inIMap
class for them.
- Since:
- 3.5
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddEntryListener
(MapListener listener, boolean includeValue) addEntryListener
(MapListener listener, Predicate<K, V> predicate, boolean includeValue) addEntryListener
(MapListener listener, Predicate<K, V> predicate, K key, boolean includeValue) addEntryListener
(MapListener listener, K key, boolean includeValue) void
addIndex
(IndexConfig config) default void
boolean
containsKey
(Object key) boolean
containsValue
(Object value) void
destroy()
Destroys this cache.entrySet()
getName()
Returns the name of thisQueryCache
.boolean
isEmpty()
keySet()
boolean
int
size()
boolean
This method can be used to recover from a possible event loss situation.values()
-
Method Details
-
get
- See Also:
-
containsKey
- See Also:
-
containsValue
- See Also:
-
isEmpty
boolean isEmpty()- See Also:
-
size
int size()- See Also:
-
addIndex
- See Also:
-
addIndex
- See Also:
-
getAll
- See Also:
-
keySet
- See Also:
-
values
Collection<V> values()- See Also:
-
entrySet
- See Also:
-
keySet
- See Also:
-
values
- See Also:
-
entrySet
- See Also:
-
addEntryListener
-
addEntryListener
-
addEntryListener
-
addEntryListener
-
removeEntryListener
- See Also:
-
getName
String getName()Returns the name of thisQueryCache
. The returned value will never be null.- Returns:
- the name of this
QueryCache
.
-
tryRecover
boolean tryRecover()This method can be used to recover from a possible event loss situation. You can detect event loss viaEventLostListener
This method tries to make consistent the data in this
QueryCache
with the data in the underlyingIMap
by replaying the events after last consistently received ones. As a result of this replaying logic, same event may appear more than once to theQueryCache
listeners.This method returns
false
if the event is not in the buffer of event publisher side. That means recovery is not possible.- Returns:
true
if theQueryCache
content will be eventually consistent, otherwisefalse
.- See Also:
-
QueryCacheConfig.bufferSize
-
destroy
void destroy()Destroys this cache. Clears and releases all local and remote resources created for this cache.
-