Interface QueryCache<K,V>

Type Parameters:
K - the type of key for this QueryCache
V - the type of value for this QueryCache

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 this QueryCache it may receive same event more than once in case of a system failure. Check out tryRecover()
  • All writes to this QueryCache is reflected to underlying IMap and that write operation will eventually be reflected to this QueryCache 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 this QueryCache. Please check gotchas section in IMap class for them.

Since:
3.5
See Also: