简体   繁体   中英

Configure query cache without second level cache

i want to configure query cache without second level cache for some learning purpose as i have read it can be done but somehow for me query cache works only with 2nd level cache.

Here is my configuration

<property name="cache.use_query_cache">true</property>

Entity class is

@Entity
public class Company {}

but when i do

session = factory.openSession();
Query getQuery=session.createQuery("from Company  where companyId=1");
getQuery.setCacheable(true);
Object company2 = getQuery.uniqueResult();
session.close();

session = factory.openSession();
getQuery=session.createQuery("from Company  where companyId=1");
getQuery.setCacheable(true);
company2 = getQuery.uniqueResult();
session.close();

Two separate queries are fired .

As soon as i do

@Entity
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Company {}

Query cache work but it enables the second level cache also. So how to configure query cache without enabling second level cache?

Query cache needs the 2nd level cache to do its job, since the results of the queries are then retrieved from the 2nd level cache. The query cache just keeps track of a query and the set of ids that the query returned. These ids are then retrieved from 2nd level cache from further speed increase. Where did you read you could have query cache without 2nd level cache?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM