com.hazelcast.map

## 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:
    `QueryCacheConfig`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `addEntryListener(MapListener listener, boolean includeValue)`
    `String` | `addEntryListener(MapListener listener, K key, boolean includeValue)`
    `String` | `addEntryListener(MapListener listener, Predicate<K,V> predicate, boolean includeValue)`
    `String` | `addEntryListener(MapListener listener, Predicate<K,V> predicate, K key, boolean includeValue)`
    `void` | `addIndex(String attribute, boolean ordered)`
    `boolean` | `containsKey(Object key)`
    `boolean` | `containsValue(Object value)`
    `void` | `destroy()` Destroys this cache.
    `Set<Map.Entry<K,V>>` | `entrySet()`
    `Set<Map.Entry<K,V>>` | `entrySet(Predicate predicate)`
    `V` | `get(Object key)`
    `Map<K,V>` | `getAll(Set<K> keys)`
    `String` | `getName()` Returns the name of this `QueryCache`.
    `boolean` | `isEmpty()`
    `Set<K>` | `keySet()`
    `Set<K>` | `keySet(Predicate predicate)`
    `boolean` | `removeEntryListener(String id)`
    `int` | `size()`
    `boolean` | `tryRecover()` This method can be used to recover from a possible event loss situation.
    `Collection<V>` | `values()`
    `Collection<V>` | `values(Predicate predicate)`

- - ### Method Detail

    - #### get

          V get(Object key)

      See Also:
        `IMap.get(Object)`

    - #### containsKey

          boolean containsKey(Object key)

      See Also:
        `IMap.containsKey(Object)`

    - #### containsValue

          boolean containsValue(Object value)

      See Also:
        `IMap.containsValue(Object)`

    - #### isEmpty

          boolean isEmpty()

      See Also:
        `Map.isEmpty()`

    - #### size

          int size()

      See Also:
        `Map.size()`

    - #### addIndex

          void addIndex(String attribute,
                        boolean ordered)

      See Also:
        `IMap.addIndex(String, boolean)`

    - #### getAll

          Map<K,V> getAll(Set<K> keys)

      See Also:
        `IMap.getAll(Set)`

    - #### keySet

          Set<K> keySet()

      See Also:
        `IMap.keySet()`

    - #### keySet

          Set<K> keySet(Predicate predicate)

      See Also:
        `IMap.keySet(Predicate)`

    - #### entrySet

          Set<Map.Entry<K,V>> entrySet()

      See Also:
        `IMap.entrySet()`

    - #### entrySet

          Set<Map.Entry<K,V>> entrySet(Predicate predicate)

      See Also:
        `IMap.entrySet(Predicate)`

    - #### values

          Collection<V> values()

      See Also:
        `IMap.values()`

    - #### values

          Collection<V> values(Predicate predicate)

      See Also:
        `IMap.values(Predicate)`

    - #### addEntryListener

          String addEntryListener(MapListener listener,
                                  boolean includeValue)

      See Also:
        `IMap.addEntryListener(MapListener, boolean)`

    - #### addEntryListener

          String addEntryListener(MapListener listener,
                                  K key,
                                  boolean includeValue)

      See Also:
        `IMap.addEntryListener(MapListener, Object, boolean)`

    - #### addEntryListener

          String addEntryListener(MapListener listener,
                                  Predicate<K,V> predicate,
                                  boolean includeValue)

      See Also:
        `IMap.addEntryListener(MapListener, Predicate, boolean)`

    - #### addEntryListener

          String addEntryListener(MapListener listener,
                                  Predicate<K,V> predicate,
                                  K key,
                                  boolean includeValue)

      See Also:
        `IMap.addEntryListener(MapListener, Predicate, Object, boolean)`

    - #### removeEntryListener

          boolean removeEntryListener(String id)

      See Also:
        `IMap.removeEntryListener(String)`

    - #### getName

          String getName()

      Returns the name of this `QueryCache`. 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 via `EventLostListener`

      This method tries to make consistent the data in this `QueryCache` with the data in the underlying `IMap` by replaying the events after last consistently received ones. As a result of this replaying logic, same event may appear more than once to the `QueryCache` 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 the `QueryCache` content will be eventually consistent, otherwise `false`.
      See Also:
        `QueryCacheConfig.bufferSize`

    - #### destroy

          void destroy()

      Destroys this cache. Clears and releases all local and remote resources created for this cache.

Copyright © 2019. All rights reserved.