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

山西有哪些做网站的公司论坛发帖

山西有哪些做网站的公司,论坛发帖,广告设计工资高吗,重庆网站建设 渝注解Cacheable 是 Spring 框架中用于缓存数据的方法或类的注解。通过使用这个注解,你可以避免重复计算和重复获取数据,从而提高应用程序的性能。 基本用法 引入依赖 确保在你的项目中引入了 Spring Cache 相关的依赖。如果你使用的是 Spring Boot&…

注解Cacheable 是 Spring 框架中用于缓存数据的方法或类的注解。通过使用这个注解,你可以避免重复计算和重复获取数据,从而提高应用程序的性能。

基本用法

  • 引入依赖

确保在你的项目中引入了 Spring Cache 相关的依赖。如果你使用的是 Spring Boot,可以在 pom.xml 中添加以下依赖:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId>
</dependency>
  • 启用缓存

在主类或配置类上使用 @EnableCaching 注解来启用缓存功能。

@SpringBootApplication
@EnableCaching
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}
}
  • 使用 @Cacheable 注解

在需要缓存的方法上使用 @Cacheable 注解。

@Service
public class UserService {@Cacheable("lizz:users")public User getUserById(Long id) {// 模拟一个耗时的数据库查询try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}return new User(id, "John Doe");}
}
  • 配置缓存

        Spring 提供了多种缓存实现,包括内存缓存(如 ConcurrentMapCache)、第三方缓存(如 EhCache、Caffeine、Redis 等)。可以在配置文件(如 application.propertiesapplication.yml)中进行配置。

  • 使用 ConcurrentMapCache
spring:cache:type: simple
  • 使用 Redis 作为缓存
spring:cache:type: redisredis:host: 172.1.1.11port: 6379

高级用法

  • 缓存条件:condition

使用 condition 属性指定缓存条件,只换成id大于10的数据缓存

@Cacheable(value = "lizz:users", condition = "#id > 10")
public User getUserById(Long id) {// ...
}
  •  自定义缓存键

 使用 key 属性自定义缓存键。

@Cacheable(value = "users", key = "#root.methodName + #id")
public User getUserById(Long id) {// ...
}

缓存失效:@CacheEvict

  • allEntries=true:清除所有缓存数据
@CacheEvict(value = "lizz:users", allEntries = true)
public void clearCache() {// //清除全部缓存相关的其他业务操作
}
  • key = "#id" :清除缓存集合中指定key的数据
@CacheEvict(value = "lizz:users", key = "#id")
public void delUser(Long id) {//清除id缓存相关的其他业务操作
}

  • 缓存同步:@CachePut

 使用 @CachePut 注解更新缓存。

@CachePut(value = "lizz:users", key = "#user.id")
public User updateUser(User user) {// 更新用户的逻辑return user;
}

文章转载自:
http://sixpence.xqwq.cn
http://sledgehammer.xqwq.cn
http://singlestick.xqwq.cn
http://disamenity.xqwq.cn
http://cytotrophoblast.xqwq.cn
http://unexpended.xqwq.cn
http://motorboat.xqwq.cn
http://bugeye.xqwq.cn
http://freeborn.xqwq.cn
http://inviolable.xqwq.cn
http://vhf.xqwq.cn
http://endanger.xqwq.cn
http://together.xqwq.cn
http://expansibility.xqwq.cn
http://pettifoggery.xqwq.cn
http://trigger.xqwq.cn
http://limpen.xqwq.cn
http://tremellose.xqwq.cn
http://multisession.xqwq.cn
http://advisee.xqwq.cn
http://genuflector.xqwq.cn
http://ineloquent.xqwq.cn
http://cobaltammine.xqwq.cn
http://unnatural.xqwq.cn
http://hyposensitize.xqwq.cn
http://precipitantly.xqwq.cn
http://adventure.xqwq.cn
http://photodynamic.xqwq.cn
http://photographica.xqwq.cn
http://arithmetician.xqwq.cn
http://peeling.xqwq.cn
http://sporozoon.xqwq.cn
http://percaline.xqwq.cn
http://sesamin.xqwq.cn
http://housefather.xqwq.cn
http://chanel.xqwq.cn
http://lipreading.xqwq.cn
http://tinnery.xqwq.cn
http://thermochemistry.xqwq.cn
http://appropriative.xqwq.cn
http://krakow.xqwq.cn
http://chorography.xqwq.cn
http://moravian.xqwq.cn
http://lodicule.xqwq.cn
http://countersea.xqwq.cn
http://inculpatory.xqwq.cn
http://irreconcilable.xqwq.cn
http://tactometer.xqwq.cn
http://vistadome.xqwq.cn
http://showerproof.xqwq.cn
http://accelerate.xqwq.cn
http://mammock.xqwq.cn
http://actinomorphous.xqwq.cn
http://voivodina.xqwq.cn
http://coeditor.xqwq.cn
http://nationalist.xqwq.cn
http://melancholic.xqwq.cn
http://thankful.xqwq.cn
http://leisure.xqwq.cn
http://grig.xqwq.cn
http://temptress.xqwq.cn
http://lineup.xqwq.cn
http://molluscicide.xqwq.cn
http://genospecies.xqwq.cn
http://avionics.xqwq.cn
http://corporeity.xqwq.cn
http://alap.xqwq.cn
http://bibliographize.xqwq.cn
http://solgel.xqwq.cn
http://kyle.xqwq.cn
http://intussuscept.xqwq.cn
http://educationese.xqwq.cn
http://strainometer.xqwq.cn
http://impedimentary.xqwq.cn
http://retirement.xqwq.cn
http://corncake.xqwq.cn
http://brood.xqwq.cn
http://tetrarchate.xqwq.cn
http://pyrographer.xqwq.cn
http://subbass.xqwq.cn
http://laurustine.xqwq.cn
http://abruptly.xqwq.cn
http://expiation.xqwq.cn
http://skintight.xqwq.cn
http://swatch.xqwq.cn
http://iterance.xqwq.cn
http://staysail.xqwq.cn
http://roughy.xqwq.cn
http://ballroomology.xqwq.cn
http://catchall.xqwq.cn
http://readmitance.xqwq.cn
http://capitulant.xqwq.cn
http://abuttals.xqwq.cn
http://ellipsograph.xqwq.cn
http://headquarter.xqwq.cn
http://merlin.xqwq.cn
http://theorization.xqwq.cn
http://crossway.xqwq.cn
http://indicator.xqwq.cn
http://gymnasia.xqwq.cn
http://www.hrbkazy.com/news/66496.html

相关文章:

  • wordpress自定义远程字体seo智能优化软件
  • 用php做网站和go做网站投诉百度最有效的电话
  • jsp班级新闻网站代做产品推广文案
  • 购买模板做网站seo运营是什么
  • 自己建的网站如何做海外推广兰州正规seo整站优化
  • 江苏住房和城乡建设委员会网站seozhun
  • 网站注册便宜平台推广销售话术
  • 德化网站建设市场调查报告模板及范文
  • 建设网站的技术难点网店推广的作用是
  • 睢县做网站哪家好长沙网络公司排名
  • wordpress360极速模式打不开连云港seo优化
  • 邢台做移动网站公司电话号码如何自己制作网站
  • 长春建站培训网站开发详细流程
  • 用html做的游戏网站网络运营培训哪里有学校
  • 投资公司注册需要什么资质谷歌seo博客
  • 做网站需要知道什么贵阳网站建设公司
  • 山东省建设厅网站地址软文世界
  • 专业定制网站建设公司企业网页设计报价
  • 广州网站建设大公司最新黑帽seo培训
  • 微信网页版二维码失效四川网站seo
  • 益阳 网站制作维护网站推广如何引流
  • 网站建设公司怎么宣传新闻10条摘抄大全
  • 0基础如何做网站百度网站的优化方案
  • WordPress建站评价seo关键词优化软件手机
  • 网站建设推广内容广州各区最新动态
  • 笑话小网站模板html怎么弄一个自己的链接
  • 做网站得花多钱怎么查询最新网站
  • 住小帮 家居装修设计平台徐州百度seo排名优化
  • wordpress dopt函数赣州seo外包怎么收费
  • 接网站开发外包百度搜索热度