zoukankan      html  css  js  c++  java
  • 快速配置Ehcache

    1. 编写ehcache.xml文件,将该文件放置于classpath路径下。代码如下:

    <?xml version="1.0" encoding="UTF-8"?>

    <ehcache>

        <!-- 缓存文件生成之后所放置的路径 -->
        <diskStore path="D:/Develop/tomcat-6.0.18/temp/cache" />

        <!-- maxElementsInMemory 缓存最大数目
             eternal 缓存是否持久 
             overflowToDisk 是否保存到磁盘,当系统宕机时
             timeToIdleSeconds 当缓存闲置n秒后销毁
             timeToLiveSeconds 当缓存存活n秒后销毁
             diskPersistent 是否在磁盘上持久化
             diskExpiryThreadIntervalSeconds 对象检测线程运行时间间隔 -->
        <defaultCache maxElementsInMemory="10000" eternal="false"
            overflowToDisk="true" timeToIdleSeconds="120" timeToLiveSeconds="120"
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120" />
    </ehcache>

    2. 配置hibernate核心xml文件,代码如下:

    <property name="hibernateProperties">
                <props>

                       ...

                    <prop   key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
                    <prop key="hibernate.cache.use_second_level_cache">true</prop>
                    <prop key="hibernate.cache.use_structured_entries">true</prop>
                    <prop key="hibernate.cache.use_query_cache">true</prop>

               </props>

    </property>

    添加上述几项关于缓存的配置

    3. 配置需要加入缓存的实体hbm文件,代码如下:

    在hbm文件的上端配置<cache usage="read-write"/>

    4. 导入ehcache.jar文件,并将其加入到buildpath下。

    完成上述4个步骤操作之后,即可启动tomcat,打开log跟踪器查看自己配置的缓存是否已达到效果。

    (同样我们也可以将步骤2中"hibernate.cache.provider_class"的值替换为”org.hibernate.cache.EhCacheProvider“ 使用Hibernate自身所带的缓存支持类,那么这个时候就可以略去步骤4了。即无需再导入ehcache jar包。)

  • 相关阅读:
    HPU第二次个人训练
    2019CCPC江西省赛
    CodeForces-913C 派对柠檬水
    [Codeforces Round #737 (Div. 2)] C Moamen and XOR (T1 D1
    E-Tree Xor_2021牛客暑期多校训练营4
    Educational Codeforces Round 107 (Rated for Div. 2) E Colorings and Dominoes
    状压dp 练习
    权值线段树模板(自用)
    Planar Reflections
    Codeforces Round #688 (Div. 2) D Checkpoints
  • 原文地址:https://www.cnblogs.com/sandea/p/3758142.html
Copyright © 2011-2022 走看看