hibernatehazelcastsecond-level-cachequery-cache

Hazelcast Hibernate Query Cache Region configuration


I am running Hazelcast 3.11 in P2P mode and Hibernate-5.3. I have configured second level cache regions with expire policies for mine entities. Now I am trying to configure expire policy for mine Query caches, but issue is, I can not find out query cache default region name and not sure if it is configurable using hazelcast maps. I have tried next configs, but with no luck:

    eviction-policy: LFU
    in-memory-format: BINARY
    name: org.hibernate.cache.internal.*
    max-size: 1000
    max-size-policy: PER_NODE
    time-to-live: 10
    time-to-idle: 10

And

    eviction-policy: LFU
    in-memory-format: BINARY
    name: default-query-results-region
    max-size: 1000
    max-size-policy: PER_NODE
    time-to-live: 10
    time-to-idle: 10

Is it possible to configure Query Cache Region using hazelcast?


Solution

  • EDIT: Depending on the cache region name set during the execution of a query, a map with this region name must be configured on the Hazelcast configuration. For instance, default-query-results-region will be used and must be configured for the following query:

    session.createQuery(QUERY_STRING).setCacheable(true);
    

    and custom-name for the following:

    session.createQuery(QUERY_STRING).setCacheable(true).setCacheRegion("custom-name");
    

    You should configure the map config either programmatically or on hazelcast.xml such that:

    <map name="default-query-results-region">
        <max-size>1000</max-size>
        <time-to-live-seconds>10</time-to-live-seconds>
    </map>    
    
    <map name="custom-name">
        <max-size>1000</max-size>
        <time-to-live-seconds>10</time-to-live-seconds>
    </map>
    

    Keep in mind that in Hazelcast L2C, query results are not cached in distributed map but a local map. A basic clean up procedure is performed periodically for evictions based only on max-size and time-to-live criteria. Other options (eviction-policy, in-memory-format, idle-time etc.) will be ignored even if you set.