首页 > 其他分享 >EHCache spring

EHCache spring

时间:2023-04-28 18:32:25浏览次数:47  
标签:EHCache www Cacheable spring cache springframework org


EHCache spring

 

 

import:

import org.springframework.cache.annotation.Cacheable;

 

 

注解(我放在service方法上,注意这个注解,如果用SPRING的Cacheable,就跟这一样;如果用GOOGLE的,这几个配置及import都得一致):

@Cacheable(value = "baseCache", key = "'myid_'+#date")

public String myMethod(String date){}

 

spring配置文件:

xmlns:cache="http://www.springframework.org/schema/cache"

 

http://www.springframework.org/schema/cache

http://www.springframework.org/schema/cache/spring-cache-3.2.xsd



<!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
	<cache:annotation-driven cache-manager="ehcacheManager"/>
	<!-- cacheManager工厂类,指定ehcache.xml的位置 -->
	<bean id="ehcacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
		<property name="configLocation" value="classpath:ehcache.xml" />
		<property name="shared" value="true"/>
	</bean>
	<!-- 声明cacheManager -->
	<bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
		<property name="cacheManager" ref="ehcacheManagerFactory" />
	</bean>



 

 

 

ehcache.xml:

 


<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">

	<diskStore path="java.io.tmpdir" />
	<defaultCache eternal="false"
	maxElementsInMemory="1000"
	overflowToDisk="false"
	diskPersistent="false"
	timeToIdleSeconds="0"
	timeToLiveSeconds="600"
	memoryStoreEvictionPolicy="LFU" />
	<!--
	eternal="false"   // 元素是否永恒,如果是就永不过期(必须设置)
	maxElementsInMemory="1000" // 缓存容量的内存最大值(必须设置)
	overflowToDisk="false"  // 当缓存达到maxElementsInMemory值是,是否允许溢出到磁盘(必须设置)
	diskPersistent="false"  // 磁盘缓存在VM重新启动时是否保持(默认为false)
	timeToIdleSeconds="0" // 导致元素过期的访问间隔(秒为单位). 0表示可以永远空闲,默认为0
	timeToLiveSeconds="600" // 元素在缓存里存在的时间(秒为单位). 0 表示永远存在不过期
	memoryStoreEvictionPolicy="LFU" // 当达到maxElementsInMemory时,如何强制进行驱逐默认使用"最近使用(LRU)"策略,其它还有先入先出FIFO,最少使用LFU,较少使用LRU
	-->
	<cache name="baseCache"
	eternal="false"
	maxElementsInMemory="100"
	overflowToDisk="false"
	diskPersistent="false"
	timeToIdleSeconds="0"
	timeToLiveSeconds="300"
	memoryStoreEvictionPolicy="LRU" />

</ehcache>



标签:EHCache,www,Cacheable,spring,cache,springframework,org
From: https://blog.51cto.com/u_9716826/6235307

相关文章

  • Spring Boot经验
    Spring、SpringBoot经验本文记录作者在实际使用Spring或则SpringBoot过程中遇到比较好的案例或则经验,以供开发学习使用1.校验篇生产过程中前后端都会进行数据格式的校验,后端校验一般采用JSR303的校验模式1.1使用引入依赖<dependency><groupId>javax.validation<......
  • Spring Boot 和 Docker 实现微服务部署
    Springboot开发轻巧的微服务提供了便利,Docker的发展又极大的方便了微服务的部署。这篇文章介绍一下如果借助maven来快速的生成微服务的镜像以及快速启动服务。其实将SpringBoot项目用Docker部署也不是什么多么神秘的技术,也要先生成镜像,再用镜像启动容器,如果说有什么方便......
  • Spring Cloud 系列之 Eureka 实现服务注册与发现
    如果你对SpringCloud体系还不是很了解,可以先读一下SpringCloud都有哪些模块Eureka是Netflix开源的服务注册发现组件,服务发现可以说是微服务架构的核心功能了,微服务部署之后,一定要有服务注册和发现的能力,Eureka就是担任这个角色的。如果你用过dubbo的话,那一定知道dubbo......
  • Spring 实现自定义 bean 的扩展
    Springmvc提供了扩展xml的机制,用来编写自定义的xmlbean,例如dubbo框架,就利用这个机制实现了好多的dubbobean,比如 <dubbo:application>、<dubbo:registry> 等等,只要安装这个标准的扩展方式实现配置即可。扩展自定义bean的意义何在假设我们要使用一个开源框架或者一套......
  • 你一直在用的 Spring Boot Starters 究竟是怎么回事
    SpringBoot对比SpringMVC最大的优点就是使用简单,约定大于配置。不会像之前用SpringMVC的时候,时不时被xml配置文件搞的晕头转向,冷不防还因为xml配置上的一点疏忽,导致整个项目莫名其妙的不可用,顿感生活无所依恋,简称生无可恋。这要归功于组成了SpringBoot的各种各样的......
  • Spring AOP 和 动态代理技术
     AOP是什么东西首先来说AOP并不是Spring框架的核心技术之一,AOP全称AspectOrientProgramming,即面向切面的编程。其要解决的问题就是在不改变源代码的情况下,实现对逻辑功能的修改。常用的场景包括记录日志、异常处理、性能监控、安全控制(例如拦截器)等,总结起来就是,凡是想对......
  • vscode下搭建springboot
    安装两个扩展JavaExtensionforPackSpringBootExtensionPack配置mavenctrl+,搜索java.configuration.maven输入setting.xml的路径注意路径不能有中文或者空格创建springboot项目ctrl+shift+p创建项目,输入springbootInitializer即可。参考博客vscode配置ma......
  • Spring源码分析之BeanFactory
    概述以XmlBeanFactory为例分析Xml描述的Bean被Reasource加载到内存,先解析为Document对象,再解析为BeanDefinition注册到BeanDefinitionRegistry,再通过BeanFactory创建名词解释Resource是Spring对资源的抽象,主要是用来读取文件输入流Document是java本身的API进行解析的,得到......
  • Spring XML配置的12个技巧
    Spring是一个强有力的java程序框架,其被广泛应用于java的程序中。它用POJO提供了企业级服务。Spring利用依赖注入可以获得简单而有效的测试能力。Springbeans,依赖关系,以及服务所需要的bean都将在配置文件中予以描述,配置文件一般采用XML格式。然而XML配置文件冗长而不易使用,在你进......
  • springcloud gateway filter 重写response
     importorg.reactivestreams.Publisher;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.cloud.gateway.filter.GatewayFilterChain;importorg.springframework.cloud.gateway.filter.GlobalFilter;importorg.springfram......