春天使用实现缓存的方法有哪些

  介绍

这篇文章给大家介绍使用弹簧实现缓存的方法有哪些,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

<强> 1,弹簧和ehcache集成

主要获取ehcache作为操作ehcache的对象。

为了中注入ehcacheManager和ehcache对象,ehcacheManager是需要加载ehcache.xml配置信息,创建ehcache。xml中配置不同策略的缓存。

& lt; !——ehCache配置管理器——比;   & lt; bean id=癳hcacheManager"类=皁rg.springframework.cache.ehcache.EhCacheManagerFactoryBean"比;   & lt;属性名=癱onfigLocation"值=https://www.yisu.com/zixun/崩嗦肪?ehcache.xml "/>      <属性名="共享" value=" true "/>   <属性名=" cacheManagerName " value=" ehcacheManager "/>         <属性名="缓存管理器“ref=" ehcacheManager "/>         <缓存:注解驱动的缓存管理器="缓存管理器"/>

& lt; !——春天自己的基于java.util.concurrent.ConcurrentHashMap实现的缓存管理器(该功能是从Spring3.1开始提供的)——比;   & lt; bean id=癱acheManager"类=皁rg.springframework.cache.support.SimpleCacheManager"比;   & lt;属性名=癱aches"祝辞   & lt; set>   & lt; bean name=癝implePageCachingFilter"类=皁rg.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"/比;   & lt;/set>   & lt;/property>   & lt;/bean>

主要获取redisTemplate作为操作复述的对象。

复述。属性配置信息

#主机写入复述,服务器地址

redis.ip=127.0.0.1

#端口redis.port=6379 # Passord

# redis.password=123456

#连接超时30000

redis.timeout=30

#最大分配的对象数

redis.pool.maxActive=100

#最大能够保持艾德尔状态的对象数

redis.pool.maxIdle=30

#当池内没有返回对象时,最大等待时间

redis.pool。maxWait=1000

#当调用借款对象方法时,是否进行有效性检查

redis.pool。testOnBorrow=true

#当调用返回对象方法时,是否进行有效性检查

redis.pool。testOnReturn=true

春注入jedisPool, redisConnFactory, redisTemplate对象

& lt; !——加载复述。同时,在      & lt; bean类=皁rg.springframework.beans.factory.config.PropertyPlaceholderConfigurer"祝辞      & lt;属性名=發ocations"值=https://www.yisu.com/zixun/崩嗦肪?redis.properties "/>       & lt; !——复述,连接池——比;      & lt; bean id=癹edisPool"类=皉edis.clients.jedis.JedisPoolConfig"比;      & lt;属性名=癿axTotal"https://www.yisu.com/zixun/value=" $ {redis.pool.maxActive} "/>      <属性名==" $ {redis.pool“maxIdle”价值。maxIdle} "/>      <属性名==" $ {redis.pool“testOnBorrow”价值。testOnBorrow} "/>      <属性名==" $ {redis.pool“testOnReturn”价值。testOnReturn} "/>      <属性名==" $ {redis.pool“maxWaitMillis”价值。maxWait} "/>       & lt; !——复述,连接工厂——比;      & lt; bean id=皉edisConnFactory"类=皁rg.springframework.data.redis.connection.jedis.JedisConnectionFactory"比;      & lt;属性名=癶ostName"https://www.yisu.com/zixun/value=" $ {redis.ip} "/>      <属性名="端口" value=" ${复述。港口}"/>            <属性名==" ${复述“超时”价值。超时}"/>      <属性名=" poolConfig“ref=" jedisPool "/>       & lt; !——复述,操作对象——比;      & lt; bean id=皉edisTemplate"类=皁rg.springframework.data.redis.core.RedisTemplate"比;      & lt;属性名=癱onnectionFactory"ref=皉edisConnFactory"/比;      & lt;/bean> & lt; !——自定义缓存——比;      & lt; bean id=癱acheManager"类=皁rg.springframework.cache.support.SimpleCacheManager"比;      & lt;属性名=癱aches"祝辞      & lt; set>      & lt; bean类=皁rg.cpframework.cache.redis.RedisCache"祝辞      & lt;属性名=皉edisTemplate"ref=皉edisTemplate"/比;      & lt;属性名=皀ame"值=https://www.yisu.com/zixun/"默认"/>      

春天使用实现缓存的方法有哪些