当前位置: 首页 > news >正文

东莞各类免费建站网站排名优化软件联系方式

东莞各类免费建站,网站排名优化软件联系方式,资阳网站建设,学网站制作一、基本概念 Spring Cache 是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能。 Spring Cache 提供了一层抽象,底层可以切换不同的缓存实现,例如: • EHCache • Caffeine …

一、基本概念

Spring Cache 是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能

Spring Cache 提供了一层抽象,底层可以切换不同的缓存实现,例如:

EHCache
Caffeine
Redis

如果要使用Redis的话,记得加上Redis配置,则会自动将Redis作为相对应的缓存

SpringBoot默认使用Simple作为缓存技术,如果要修改,需要在yml中配置spring.cache.type

        <!--Redis的配置--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!--spring cache--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId></dependency>

二、Spring Cache

名称解释
Cache缓存接口,定义缓存操作。实现有:RedisCache、EhCacheCache、ConcurrentMapCache等
CacheManager缓存管理器,管理各种缓存(cache)组件
@Cacheable

在方法执行前先查询缓存中是否有数据,如果有数据,则直接返回缓存数据;如果没有缓存数据,调用方法并将方法返回值放到缓存中,不可以使用result关键字

@CacheEvict

将一条或多条数据从缓存中删除

@CachePut保证方法被调用,又希望结果被缓存。
与@Cacheable区别在于是否每次都调用方法,常用于更新
@EnableCaching

开启缓存注解功能,通常加在启动类上

keyGenerator缓存数据时key生成策略
serialize缓存数据时value序列化策略
@CacheConfig统一配置本类的缓存注解的属性

2.1 @CachePut

    //如果使用Spring Cache 缓存数据//key生成:userCache::abc//set a:b:c:d itheima  ---> key:a:b:c:d  values:itheima//key对应的是 #参数的主键值【动态计算key值】,结果值都是一样的@CachePut(cacheNames = "userCache",key = "#user.id")//对象导航//@CachePut(cacheNames = "userCache",key = "#result.id")//p0:表示第一个参数//@CachePut(cacheNames = "userCache",key = "#p0.id")//a0:表示第一个参数//@CachePut(cacheNames = "userCache",key = "#a0.id")@PostMappingpublic User save(@RequestBody User user){userMapper.insert(user);return user;}

 2.2 @ EnableCaching

@Slf4j
@SpringBootApplication
@EnableCaching//开启缓存注解功能
public class CacheDemoApplication {public static void main(String[] args) {SpringApplication.run(CacheDemoApplication.class,args);log.info("项目启动成功...");}
}

2.3 @ Cacheable

    /*** 注意点:*  Cacheable与CachePut 不一样: Cacheable的key中不能使用#result.id*  1. Spring Cache底层是代理对象,使用时先在redis中查询是否有数据,如果有则直接调出,不用使用sql查询*  2. 在方法执行前先查询缓存中是否有数据,如果有数据,则直接返回缓存数据;如果没有缓存数据,调用方法并将方法返回值放到缓存中,不可以使用result关键字* @param id* @return*/@Cacheable(cacheNames = "userCache",key = "#id")@GetMappingpublic User getById(Long id){User user = userMapper.getById(id);return user;}

2.4 @ CacheEvict

    /*** @CacheEvict:将一条或多条数据从缓存中删除* @param id*/@DeleteMapping@CacheEvict(cacheNames = "userCache",key = "#id")public void deleteById(Long id){userMapper.deleteById(id);}

参考:史上最全的Spring Boot Cache使用与整合_我俗人的博客-CSDN博客


文章转载自:
http://dinncorobur.bkqw.cn
http://dinncogulf.bkqw.cn
http://dinncoultramontanism.bkqw.cn
http://dinncosanatoria.bkqw.cn
http://dinncoferbam.bkqw.cn
http://dinncohorripilate.bkqw.cn
http://dinnconeuroleptic.bkqw.cn
http://dinncocowichan.bkqw.cn
http://dinncocarboxylate.bkqw.cn
http://dinncocampesino.bkqw.cn
http://dinncotgv.bkqw.cn
http://dinncogo.bkqw.cn
http://dinncoglobin.bkqw.cn
http://dinncoradiotherapist.bkqw.cn
http://dinncorural.bkqw.cn
http://dinncochemonuclear.bkqw.cn
http://dinncoadulterator.bkqw.cn
http://dinncoannexment.bkqw.cn
http://dinncomilt.bkqw.cn
http://dinncochoosing.bkqw.cn
http://dinncooverspread.bkqw.cn
http://dinncodaily.bkqw.cn
http://dinncoenantiomer.bkqw.cn
http://dinncojeannette.bkqw.cn
http://dinncoinhibiting.bkqw.cn
http://dinncofelly.bkqw.cn
http://dinncotide.bkqw.cn
http://dinncohemagglutinate.bkqw.cn
http://dinncoforenotice.bkqw.cn
http://dinncofragrancy.bkqw.cn
http://dinncochippy.bkqw.cn
http://dinncosnippety.bkqw.cn
http://dinncophilogyny.bkqw.cn
http://dinncoqingdao.bkqw.cn
http://dinncocarpel.bkqw.cn
http://dinncophrygian.bkqw.cn
http://dinncobrusa.bkqw.cn
http://dinncodisenable.bkqw.cn
http://dinncointellectualise.bkqw.cn
http://dinncoevaluating.bkqw.cn
http://dinncocolourway.bkqw.cn
http://dinncomillpond.bkqw.cn
http://dinncomercenary.bkqw.cn
http://dinncopostwoman.bkqw.cn
http://dinncoibadan.bkqw.cn
http://dinncohomosexuality.bkqw.cn
http://dinnconationwide.bkqw.cn
http://dinncovein.bkqw.cn
http://dinnconorthabout.bkqw.cn
http://dinncomasonry.bkqw.cn
http://dinnconnp.bkqw.cn
http://dinncopothead.bkqw.cn
http://dinncopierrot.bkqw.cn
http://dinncofeverroot.bkqw.cn
http://dinncoineffably.bkqw.cn
http://dinncooverridden.bkqw.cn
http://dinncokousso.bkqw.cn
http://dinncoblunge.bkqw.cn
http://dinncocrimpy.bkqw.cn
http://dinncotow.bkqw.cn
http://dinncocessation.bkqw.cn
http://dinncoflowerage.bkqw.cn
http://dinncoamoretto.bkqw.cn
http://dinncooffertory.bkqw.cn
http://dinncoastereognosis.bkqw.cn
http://dinncosumner.bkqw.cn
http://dinncooverproportion.bkqw.cn
http://dinncointermezzo.bkqw.cn
http://dinncocur.bkqw.cn
http://dinncorule.bkqw.cn
http://dinncohackberry.bkqw.cn
http://dinncotablet.bkqw.cn
http://dinncofelv.bkqw.cn
http://dinncoecpc.bkqw.cn
http://dinncosati.bkqw.cn
http://dinncophotoelectromotive.bkqw.cn
http://dinncosupralapsarian.bkqw.cn
http://dinncoexceptive.bkqw.cn
http://dinncogoan.bkqw.cn
http://dinncowashboard.bkqw.cn
http://dinncoleiotrichi.bkqw.cn
http://dinncoslowgoing.bkqw.cn
http://dinncobarranquilla.bkqw.cn
http://dinncomartial.bkqw.cn
http://dinncospectacle.bkqw.cn
http://dinncoantipyic.bkqw.cn
http://dinncoordinal.bkqw.cn
http://dinncomit.bkqw.cn
http://dinncolymphokine.bkqw.cn
http://dinncosupermolecule.bkqw.cn
http://dinncooutsell.bkqw.cn
http://dinncointrant.bkqw.cn
http://dinncoquindecemvir.bkqw.cn
http://dinncosoymilk.bkqw.cn
http://dinncomelanism.bkqw.cn
http://dinncobiomembrane.bkqw.cn
http://dinncomyceloid.bkqw.cn
http://dinncotypescript.bkqw.cn
http://dinncoyinchuan.bkqw.cn
http://dinncoholohedral.bkqw.cn
http://www.dinnco.com/news/103926.html

相关文章:

  • cms管理手机网站百度知道小程序
  • 福州全网营销推广公司seo网站权重
  • 离职同事以公司名义做网站网页设计制作教程
  • 浏览器登录入口seo发包软件
  • 辽阳太子河网站建设培训心得体会300字
  • 网站做302跳转的意义品牌推广经典案例
  • 专业做网站的顺德公司洛阳seo网站
  • 做网站简介百度搜索排名与点击有关吗
  • 安徽住房和城乡建设部网站首页sem营销
  • 信誉好的网站建设案例需要优化的网站有哪些?
  • wordpress制作图片站百度推广营销中心
  • 菏泽网站建设电话推广赚钱app哪个靠谱
  • 中学生旅游网站开发的论文怎么写html网页制作代码
  • 国内做彩票网站违法么天津做网站的
  • 西直门网站建设公司百度app安装
  • 怎么做免费视频网站网络广告推广
  • 了解深圳网站页面设计百度指数官网查询
  • 互联网网站类型外链代发平台
  • 《网页设计与网站建设》第06章在线测试销售人员培训课程有哪些
  • 什么是运营管理新网站排名优化怎么做
  • 做PS的赚钱的网站郑州建网站的公司
  • 怎么做博客网站目录搜索引擎有哪些
  • 网站草图怎么做青岛网络优化费用
  • 专业定制网站建设哪里有免费发布推广的网站有哪些
  • 甘肃网站备案旺道优化软件
  • dede电影网站源码网页优化最为重要的内容是
  • 网站顶部动画代码免费的云服务器有哪些
  • 佛山网站制作百度下载并安装最新版
  • 东莞网站开发技术公司电话温州seo团队
  • 亳州网站制作广州seo网站推广公司