Hibernate level Two cache vs query caching (Second cache vs queries Cache)
These two concepts, because of the importance of the query cache is not enough, easy to mix. In comparison with the following dimensions:
1. Processing time
2. Cache format
3. Scope of application
4. A little analysis of the pros and cons of processing time
Description:
1. query cache before the level one or two cache , enabling circumstances, first to find the contents of the query cache;
2. all caches must be after calling HQL , the code must go to the HQL block, and then by Hibernate black-boxes operation. This differs from spring's caching mechanism. Cache Format
level one or two cache |
Query Caching |
Id:entity object of record |
Key value calculated by the HQL statement: ID of the record |
Description:
1. The basic content (Key:value) is generally understood to be a form of key-value;
2. query Cache key value calculation, will be included in the HQL statement of all the details , including query conditions, paging, and so on; scope of application
First-
level caching |
Level Two cache |
Query Caching |
Session |
Sessionfactory |
Sessionfactory |
Description:
Whether the scope of the query cache can span sessionfactory. Pending further study. analyze the pros and cons slightly:
1. query cache must be combined with the secondary cache , otherwise from the query cache to get the ID of the record, but also to check the database;
2. The secondary cache can only improve performance by ID , because the stored key value is the record ID;
3. careful use of query caching , the key value covers the details of the HQL statement, if the query conditions often change, low cache hit rate, but will affect efficiency;
4. not suitable for the data often changed , if the data changes long, but fewer queries, will only increase the cache overhead.
In summary: Level one or two cache, or query caching, and can not improve the universal performance, specific problems have to be specific analysis. Reference:
1.http://blog.csdn.net/mydwr/article/details/8052802
2.http://blog.csdn.net/liu372267001/article/details /6422494
3.http://blog.sina.com.cn/s/blog_614cb62d0100fkp6.html
4.http://blog.163.com/tsing_hua/blog/ static/13962222420109222349921
5.http://www.cnblogs.com/wean/archive/2012/05/16/2502724.html
6. Lightweight Java EE Enterprise Application Combat (4th edition) "