# Interface QueryCache

All Known Implementing Classes:
  `MapQueryCache, NestedQueryCache`

public interface QueryCache
Defines API of a cache that stores query results.

Since:
  3.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Deprecated.
  use implementation specific methods to perform cache management tasks.
  `List`
  `get(QueryMetadata metadata)`
  Returns a cached query result for the given QueryMetadata or null if the result is not cached or is expired.
  `List`
  `get(QueryMetadata metadata, QueryCacheEntryFactory factory)`
  Returns a cached query result for the given QueryMetadata.
  `void`
  `put(QueryMetadata metadata, List results)`
  `void`
  `remove(String key)`
  Removes a single entry from cache.
  `void`
  `removeGroup(String groupKey)`
  Removes a group of entries identified by group key.
  `void`
  `removeGroup(String groupKey, Class<?> keyType, Class<?> valueType)`
  Removes a group of entries identified by group key.

- ## Method Details

  - ### get

    List get(QueryMetadata metadata)
    Returns a cached query result for the given QueryMetadata or null if the result is not cached or is expired.

  - ### get

    List get(QueryMetadata metadata, QueryCacheEntryFactory factory)
    Returns a cached query result for the given QueryMetadata. If the result is not cached or is expired, cache will use provided factory to rebuild the value and store it in the cache. A corollary is that this method never returns null.

    Compared to `get(QueryMetadata)`, this method allows the cache to do appropriate synchronization when refreshing the entry, preventing multiple threads from running the same query when a missing entry is requested by multiple threads simultaneously.

  - ### put

    void put(QueryMetadata metadata, List results)

  - ### remove

    void remove(String key)
    Removes a single entry from cache.

  - ### removeGroup

    void removeGroup(String groupKey)
    Removes a group of entries identified by group key. Note that depending on implementation this method may either actively remove the entries belonging to the group or just mark them as expired, so that they are refreshed on the next access. In the former case the cache size would shrink, but in the later the cache size will not change after calling this method.

  - ### removeGroup

    void removeGroup(String groupKey, Class<?> keyType, Class<?> valueType)
    Removes a group of entries identified by group key. Can be used if cache provider supports strictly typed caches.
    Since:
      4.0
    See Also:
      - `removeGroup(String)`

  - ### clear

    @Deprecated(since="4.0") void clear()
    Deprecated.
    use implementation specific methods to perform cache management tasks.
    Clears all cache entries.