1、 First of all, of course EHCache dependent jar package

These packages don't need to be downloaded separately , stay Hibernate Official website download Hibernate4.1.7 The package ( Such as :hibernate-release-4.1.7.Final.zip) decompression , introduce hibernate-release-4.1.7.Final\hibernate-release-4.1.7.Final\lib\optional\ehcache In the catalog ehcache-core-2.4.3.jar、hibernate-ehcache-4.1.4.Final.jar、slf4j-api-1.6.1.jar Three jar Bag can ( Is to add to referenced libraries Next ).

2、 In the project classpath Write it in the root directory of EHCache Configuration file for ehcache.xml

This configuration file can go directly to HIBERNATE_HOME\project\etc\ehcache.xml copy to src Under the directory .( There are 3 An example , All you need is a default cache configuration )

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ehcache>
  3. <diskStore path="java.io.tmpdir"/>
  4. <defaultCache
  5. maxElementsInMemory="10000" <!--  Maximum number of caches  -->
  6. eternal="false" <!--  Whether the cache is persistent  -->
  7. overflowToDisk="true" <!--  Save to disk , When the system crashes -->
  8. timeToIdleSeconds="300" <!--  When the cache is idle n Destroy in seconds  -->
  9. timeToLiveSeconds="180" <!--  When the cache is alive n Destroy in seconds -->
  10. diskPersistent="false"
  11. diskExpiryThreadIntervalSeconds= "120"/>
  12. </ehcache>

3、 stay Hibernate Enable... In the configuration file EHCache

Explain : If not set “ The query cache ”, that hibernate Only cache use load() Method , If you want to cache using findall()、list()、Iterator()、createCriteria()、createQuery() And so on , You need to set... In the configuration file hibernate.cache.use_query_cache true Talent

  1. <!--  Enable L2 cache  -->
  2. <property name="cache.use_second_level_cache">true</property>
  3. <!--  Turn on query cache  -->
  4. <property name="hibernate.cache.use_query_cache">true</property>
  5. <!--  To configure RegionFactory by Ehcache Of RegionFactory -->
  6. <property name="cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</property>

4、 Configure which entity class objects need secondary caching

stay Hibernate The configuration file hibernate.cfg.xml Unified configuration in ( recommend )

Be careful , This <class-cache> The label must be placed on <mapping> Behind the label !!

  1. <!--
  2. Configure which entity class objects need secondary caching
  3. usage Property is cache policy
  4. -->
  5. <class-cache usage="read-only" class="com.ru.domain.Student"/>

Explain : If not set “ The query cache ”, that hibernate Only cache use load() Method , If you want to cache using findall()、list()、Iterator()、createCriteria()、createQuery() And so on , You need to set... In the configuration file  hibernate.cache.use_query_cache true Talent

    1. <!--  Turn on query cache  -->
    2. <property name="hibernate.cache.use_query_cache">true</property>

Hibernate4.1.4 Configure the secondary cache EHCache More articles on steps

  1. ( turn ) by Spring Integrated Hibernate Configure the secondary cache

    http://blog.csdn.net/yerenyuan_pku/article/details/52896195 We've integrated Spring4.2.5+Hibernate4.3.11+Str ...

  2. Hibernate4+EhCache Configure the secondary cache

    This article mainly talks about Hibernate+EhCache Configure the basic usage of L2 cache ( of EhCache For a basic introduction to the :http://sjsky.iteye.com/blog/1288257 ) Cache ...

  3. Second level cache EhCache Summary of configuration methods and steps in several application technologies

    One :Spring and Ehcache Cache Integration The business problem : If the warehouse doesn't change very often , In and out of the warehouse , Always need to query warehouse list ( The list repeats ) , Use cache optimization ! read spring standard 29 chapter First step : Import ehcache Of ...

  4. Hibernate-ORM:16.Hibernate Level 2 cache in Ehcache Configuration of

    ------------ I have no other , Only hand ripe , Humble as a fool , Eager to learn ------------- This blog is about Hibernate Second level cache configuration in , What the author will use is ehcache cache One , Catalog 1. The second level cache has ...

  5. mybatis(4)_ The second level cache is deep _ Use of third parties ehcache Configure the secondary cache

    The impact of addition, deletion and modification on L2 cache 1. Adding, deleting and modifying will also clear the L2 cache 2. To clear the L2 cache is essentially to value Empty as null,key There is still a , It's not going to be Entry<k,v> Delete 3. from DB In the middle of select check ...

  6. Hibernate+EhCache Configure the secondary cache

    step : First step : Join in ehcache.jar The second step : stay src Create a new file in the directory , be known as :ehcache.xml The third step : stay hibernate Profile's <session-factory> Lower allocation ...

  7. hibernate Second level cache ehcache hibernate Configuration details

    <!-----------------hibernate Second level cache ehcache------------------------->hibernate To configure  <prop key=&quo ...

  8. hibernate Second level cache ehcache

    And Session The opposite is ,SessionFactory The corresponding caching mechanism is also provided .SessionFactory Cache can be divided into internal cache and external cache according to different functions and purposes . SessionFactory The built-in buffer ...

  9. SSH Consolidate and configure L2 cache

    One . understand Hibernate Of session Provides a level 1 Cache , Every session, To the same id Do it twice load, Not sending two sql To the database , but session closed , L1 cache failure . The L2 cache is Sessio ...

Random recommendation

  1. css Breadcrumb navigation number

    content:counter(flag);counter-increment: flag;--> The navigation bar is usually numbered 1,2,3

  2. Hadoop-2.2.0 ( Pass on hadoop-2.2.0.tar.gz)

    To configure hadoop 2.1 Upload hadoop package 2.2 decompression hadoop package First, create a cloud Catalog mkdir /cloud tar -zxvf hadoop-2.2.0.tar.gz - ...

  3. Spring and Hibernate Integrated configuration

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  4. C# The standard higher order function of functional programming

    What is a higher order function You may not be familiar with this term , But what this noun expresses is something we often use . As long as the parameters of our function can receive the function , Or functions can return functions , Of course, dynamic generation is also included . So we call this kind of function higher order function ...

  5. Java Memory area and object creation process

    One .java Memory area Java Virtual machine is executing Java In the process of the program, the memory it manages will be divided into several different data areas . Each of these areas has its own purpose , And when it was created and destroyed , Some regions exist with the start of virtual machine process , In some areas ...

  6. shift and Algorithm

    1. CF 914F Substrings in a String Carelessness : Given a string s, q A asked , (1) Single point modification , (2) inquiry [l,r] In range string y Number of occurrences of . shift and Algorithm board sub problem #p ...

  7. stay Win32 Embedded in program Edge Browser components

    The code is untested , Just make a note It's said that it's just changed UA. Modify the path in the registry , And add your own programs , Write a browser control version number , Just above 12000 It's automatically changed to Edge. For 64bit application ...

  8. In website development , You can set security , Not to be copied and F12

    No small functions // Do not right click document.oncontextmenu = function () { return false } // prohibit f12 document.onkeydown = func ...

  9. DOM How to get elements

    DOM:document object module Document object model DOM It's about describing the whole html Graph of node relationship in page , Here's the picture . 1, adopt ID, How to get elements in a page :( The context must be document) do ...

  10. &lt;20190102&gt; Include some low-level errors caused by the motherboard failure phenomenon

    There are two low-level mistakes in today's collection . The fault phenomenon :    The water-cooled exhaust fan runs at high speed , It's not regulated . Now? CPU Three lines have been designed for cooling water rows ,    temperature control 4Pin , Pump line 3Pin  , Connected to the chassis USB A light wire or ...