Home » Java » Hibernate caching policy two

Hibernate caching policy two

follows the hibernate cache in last blog, , and we continue to query cache.


Three, query caching

query cache, Gu Ming which is produced when the query buffer, then ask, just in a cache, cache in the two level load, get is not the same query? What kind of

query?

is a common attribute for the cache cache query result set, the entity object result set caching only ID, the real ID is the ID of the object, and it is related to the query conditions, where conditions, different query conditions, the cache ID is not the same as where and age > 10. Where age >18 is the two different query cache ID.


life cycle
When the

currently associated table is modified, or when the query condition changes, then the query cache life cycle ends with.


Query caching conditions

has a buffer that needs to be used for repeated queries. If you don't have the two query, the existing buffer is not working,.


then we're talking about the two level cache, what's the relationship between the two level cache and the query cache?


mentioned in the previous section that level two caches are cached entity objects and do not cache common attribute result sets, whereas query caching is a complement to level 1, two level cache, and cache.

for non entity result sets
Use:

    The
  • query buffer is generally set in the list () method.


  • The
  • query buffer must tell hibernate that the query buffer will take effect using the query buffer.

    Step 1: set
  • in CFG

< - - enable query caching, by default, false is not enabled, -->
<property name=, "hibernate.cache.use_query_cache", ">trueproperty>
"

second step: use

in the program
 query.setCacheable (true);

, this is the query cache.


Four, summary
The

cache should be used with caution, supplemented by the use of the Hibernate two level cache:


1) data that is rarely modified by

2) data that is not important, allowing occasional concurrent data

3) data that will not be accessed concurrently

4) constant data



Data unsuitable for storage to level second cache



1) data that is often modified

2) absolutely do not allow concurrent access to data, such as financial data, absolutely no concurrent
is allowed
3) shared data with other applications.


finally cited the previous words on the network to everyone:


don't think cache will most probably it did not actually happen only in improving performance, you can manage it and the right conditions is the two level cache limit such.Hibernate or more, not easy to use JDBC may greatly reduce the update performance. In the understanding of the principle under the condition of indiscriminate use, there may be 1+N the problem. Improper use can also lead to read dirty data. If the restrictions can not stand hibernate, then in your application level to do it.
cache
Do the cache in the higher level, although the effect will be better. Just like the disk cache database is to achieve its own cache, although the database cache, the application we still need to do because the underlying cache cache. It does not know what to do with the high-level data, can only be more generic, and can the realization of high-level cache, so do the cache at a higher level, the effect of it is better

.



copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest