Query cache

Query caching is not enabled by default. To use Query caching we need to explicitly enable it on the @Cache mapping annotation for the entity bean types we want to use it.

Enabling query cache

The example below enables query caching on the Customer entity bean.

@Cache(enableQueryCache=true)
@Entity
public class Customer {
  ...
}

setUseQueryCache(true)

To use the query cache you have to explicitly specify its use on a query.

// use the query cache
List<Country> list = DB.find(Country.class)
  .setUseQueryCache(true)
  .where().ilike("name", "New%")
  .findList();

The query cache is generally useful for returning lists that are very infrequently changed. These lists would often be used to populate drop down lists / combo boxes in user interfaces.

If you are familiar with the term "Lookup Tables" or "Reference Tables" these are typical candidates for using cached queries. Some examples of lookup/reference tables could be, countries, currencies and order status.

Query cache lists are read only.

@CacheQueryTuning

All query caching implementations (including Hazelcast and Apache Ignite) uses near caches and can be tuned using @CacheQueryTuning.

@Cache(enableQueryCache=true)
@CacheQueryTuning(maxSecsToLive = 30)
@Entity
public class Product  {