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 anIMap
. It can be also thought of as an always up to date view or snapshot of theIMap
. Typically,QueryCache
is used for performance reasons. ThisQueryCache
can be configured viaQueryCacheConfig
. 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 byIMap
eviction are not reflected to this cache. But the events published after an explicit call toIMap.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:
QueryCacheConfig
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.UUID
addEntryListener(MapListener listener, boolean includeValue)
java.util.UUID
addEntryListener(MapListener listener, Predicate<K,V> predicate, boolean includeValue)
java.util.UUID
addEntryListener(MapListener listener, Predicate<K,V> predicate, K key, boolean includeValue)
java.util.UUID
addEntryListener(MapListener listener, K key, boolean includeValue)
void
addIndex(IndexConfig config)
default void
addIndex(IndexType type, java.lang.String... attributes)
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
void
destroy()
Destroys this cache.java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
java.util.Set<java.util.Map.Entry<K,V>>
entrySet(Predicate<K,V> predicate)
V
get(java.lang.Object key)
java.util.Map<K,V>
getAll(java.util.Set<K> keys)
java.lang.String
getName()
Returns the name of thisQueryCache
.boolean
isEmpty()
java.util.Set<K>
keySet()
java.util.Set<K>
keySet(Predicate<K,V> predicate)
boolean
removeEntryListener(java.util.UUID id)
int
size()
boolean
tryRecover()
This method can be used to recover from a possible event loss situation.java.util.Collection<V>
values()
java.util.Collection<V>
values(Predicate<K,V> predicate)
-
-
-
Method Detail
-
get
V get(java.lang.Object key)
- See Also:
IMap.get(Object)
-
containsKey
boolean containsKey(java.lang.Object key)
- See Also:
IMap.containsKey(Object)
-
containsValue
boolean containsValue(java.lang.Object value)
- See Also:
IMap.containsValue(Object)
-
isEmpty
boolean isEmpty()
- See Also:
Map.isEmpty()
-
size
int size()
- See Also:
Map.size()
-
addIndex
default void addIndex(IndexType type, java.lang.String... attributes)
- See Also:
IMap.addIndex(IndexType, String...)
-
addIndex
void addIndex(IndexConfig config)
- See Also:
IMap.addIndex(IndexConfig)
-
getAll
java.util.Map<K,V> getAll(java.util.Set<K> keys)
- See Also:
IMap.getAll(Set)
-
keySet
java.util.Set<K> keySet()
- See Also:
IMap.keySet()
-
values
java.util.Collection<V> values()
- See Also:
IMap.values()
-
entrySet
java.util.Set<java.util.Map.Entry<K,V>> entrySet()
- See Also:
IMap.entrySet()
-
keySet
java.util.Set<K> keySet(Predicate<K,V> predicate)
- See Also:
IMap.keySet(Predicate)
-
values
java.util.Collection<V> values(Predicate<K,V> predicate)
- See Also:
IMap.values(Predicate)
-
entrySet
java.util.Set<java.util.Map.Entry<K,V>> entrySet(Predicate<K,V> predicate)
- See Also:
IMap.entrySet(Predicate)
-
addEntryListener
java.util.UUID addEntryListener(MapListener listener, boolean includeValue)
-
addEntryListener
java.util.UUID addEntryListener(MapListener listener, K key, boolean includeValue)
-
addEntryListener
java.util.UUID addEntryListener(MapListener listener, Predicate<K,V> predicate, boolean includeValue)
-
addEntryListener
java.util.UUID addEntryListener(MapListener listener, Predicate<K,V> predicate, K key, boolean includeValue)
-
removeEntryListener
boolean removeEntryListener(java.util.UUID id)
- See Also:
IMap.removeEntryListener(UUID)
-
getName
java.lang.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.
-
-