zoukankan      html  css  js  c++  java
  • 缓存 ehcache

    只是用于自己记录,防止日后忘记,回看所用

    第一步:配置ehcahe 缓存

    <?xml version="1.0" encoding="UTF-8"?>
    
    <ehcache>
        <!--
              磁盘存储:将缓存中暂时不使用的对象,转移到硬盘,类似于Windows系统的虚拟内存
               path:指定在硬盘上存储对象的路径
        -->
        <diskStore path="C:ehcache" />
    
        <!--
             defaultCache:默认的缓存配置信息,如果不加特殊说明,则所有对象按照此配置项处理
             maxElementsInMemory:设置了缓存的上限,最多存储多少个记录对象
             eternal:代表对象是否永不过期
             overflowToDisk:当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中
        -->
        <defaultCache
                maxElementsInMemory="100"
                eternal="true"
                overflowToDisk="true"/>
    
        <!--
            下面这是自己配置了一个缓存
        -->
        <cache
                name="a"
                maxElementsInMemory="100"
                eternal="true"
                overflowToDisk="true"/>
    </ehcache>

    第二步: 整合spring 和 ehcahe(即将ehcache 以bean的方式注入到 IOC 容器中)

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:cache="http://www.springframework.org/schema/cache"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="
               http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd
               http://www.springframework.org/schema/cache
               http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">
    
        <bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:ehcache.xml" />
            <property name="shared" value="true"/>
        </bean>
    
        <!-- 开启spring缓存 -->
        <!-- 注解开发启动 -->
        <cache:annotation-driven cache-manager="cacheManager" />
    
        <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
            <property name="cacheManager" ref="ehCacheManager"></property>
        </bean>
    </beans>

    第三步: 就可以在方法或者其他位置上使用注解驱动,来使用缓存技术啦

    (后期有待完善,望体谅)

  • 相关阅读:
    Console命令,让js调试更简单
    Java练习 SDUT-2192_救基友记2
    Java练习 SDUT-2246_时间日期格式转换
    SDUT-3362_村村通公路
    SDUT-2139_从起始点到目标点的最短步数(BFS)
    SDUT-3361_迷宫探索
    SDUT-2138_判断可达性
    SDUT-2107_图的深度遍历
    SDUT-2124_基于邻接矩阵的广度优先搜索遍历
    Java练习 SDUT-2787_加密术
  • 原文地址:https://www.cnblogs.com/helloqiufei/p/11756621.html
Copyright © 2011-2022 走看看