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

怎么自己制作网页新闻关键词自动优化

怎么自己制作网页新闻,关键词自动优化,如何在网站搜关键字,湖南人文科技学院宿舍什么是Spring Cache? Spring Cache是Spring框架的一个模块,它提供了对应用程序方法级别的缓存支持。通过使用Spring Cache,您可以在方法的结果被计算后,将其缓存起来,从而避免相同输入导致的重复计算。 Spring Cache…

什么是Spring Cache?

Spring Cache是Spring框架的一个模块,它提供了对应用程序方法级别的缓存支持。通过使用Spring Cache,您可以在方法的结果被计算后,将其缓存起来,从而避免相同输入导致的重复计算。

Spring Cache的工作原理

Spring Cache基于注解的方式工作。当您在方法上添加了Spring Cache提供的缓存注解后,Spring会在执行方法前先检查缓存中是否已经存在了方法的返回值。如果缓存中已经有了结果,那么Spring将直接从缓存中获取返回值,并且不会再执行实际的方法体。如果缓存中没有结果,Spring会执行方法的实际逻辑,并将返回值存储到缓存中,以备将来使用。

Spring Cache支持各种缓存提供商,例如Ehcache、Caffeine、Redis等,您可以根据需求来选择合适的缓存实现。

Spring Cache的常用注解

  1. @EnableCaching : 开启缓存注解功能,通常加在启动类上

  2. @CachePut: 该注解也标记在方法上,用于指示方法的结果应该被缓存,但是它在每次调用后都会执行方法体,并将返回值更新到缓存中。

  3. @CacheEvict: 该注解标记在方法上,用于从缓存中移除一个或多个条目。可以指定多个缓存名称或者缓存键,当方法执行时,相关的缓存条目将被从缓存中清除。

  4. @Cacheable: 在方法执行前先查询缓存中是否有数据,如果有数据,则直接返回缓存数据;如果没有缓存数据,调用方法并将方法返回值放到缓存中

Spring Cache的使用场景

Spring Cache非常适合以下情况:

  1. 频繁访问数据库或其他资源,通过缓存避免重复查询;
  2. 计算成本较高的方法,通过缓存避免重复计算;
  3. 实时性要求不高的数据,例如配置信息等;
  4. 一些通用且不经常改变的数据,例如地区信息、常量等。

起步依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache<artifactId><version>2.7.3</version> 
</dependency>

入门案例

数据库准备:

创建名为spring_cache_demo数据库,将springcachedemo.sql(如下:👇)脚本直接导入数据库中。

DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (`id` bigint NOT NULL AUTO_INCREMENT,`name` varchar(45) DEFAULT NULL,`age` int DEFAULT NULL,PRIMARY KEY (`id`)
);

引导类上加@EnableCaching:

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

@CachePut注解

@CachePut 说明:

作用: 将方法返回值,放入缓存
value: 缓存的名称, 每个缓存名称下面可以有很多key
​key: 缓存的key ----------> 支持Spring的表达式语言SPEL语法

在save方法上加注解@CachePut
当前UserController的save方法是用来保存用户信息的,我们希望在该用户信息保存到数据库的同时,也往缓存中缓存一份数据,我们可以在save方法上加上注解 @CachePut,用法如下:

	/*** CachePut:将方法返回值放入缓存* value:缓存的名称,每个缓存名称下面可以有多个key* key:缓存的key*/@PostMapping@CachePut(value = "userCache", key = "#user.id")//key的生成:userCache::1public User save(@RequestBody User user){userMapper.insert(user);return user;}

说明:

#user.id 常用: #user指的是方法形参的名称, id指的是user的id属性 , 也就是使用user的id属性作为key ;
#result.id : #result代表方法返回值,该表达式 代表以返回对象的id属性作为key ;
#p0.id:#p0指的是方法中的第一个参数,id指的是第一个参数的id属性,也就是使用第一个参数的id属性作为key ;
#a0.id:#a0指的是方法中的第一个参数,id指的是第一个参数的id属性,也就是使用第一个参数的id属性作为key ;
#root.args[0].id:#root.args[0]指的是方法中的第一个参数,id指的是第一个参数的id属性,也就是使用第一个参数的id属性作为key ;

@Cacheable

@Cacheable 说明:

作用: 在方法执行前,spring 先查看缓存中是否有数据,如果有数据,则直接返回缓存数据;若没有数据,调用方法并将方法返回值放到缓存中
cacheNames: 缓存的名称,每个缓存名称下面可以有多个key
key: 缓存的key ----------> 支持Spring的表达式语言SPEL语法

在getById上加注解@Cacheable

/**
* Cacheable:在方法执行前spring先查看缓存中是否有数据,如果有数据,则直接返回缓存数据;若没有数据,	  *调用方法并将方法返回值放到缓存中
* cacheNames:缓存的名称,每个缓存名称下面可以有多个key
* key:缓存的key
*/
@GetMapping
@Cacheable(cacheNames = "userCache",key="#id")
public User getById(Long id){User user = userMapper.getById(id);return user;
}

@CacheEvict

@CacheEvict 说明:

作用: 清理指定缓存
​ cacheNames: 缓存的名称,每个缓存名称下面可以有多个key
​ key: 缓存的key ----------> 支持Spring的表达式语言SPEL语法

在 delete 方法上加注解@CacheEvict

@DeleteMapping
@CacheEvict(cacheNames = "userCache",key = "#id")//删除某个key对应的缓存数据
public void deleteById(Long id){userMapper.deleteById(id);
}@DeleteMapping("/delAll")
@CacheEvict(cacheNames = "userCache",allEntries = true)//删除userCache下所有的缓存数据
public void deleteAll(){userMapper.deleteAll();
}

文章转载自:
http://wanjiagreenhouse.bpcf.cn
http://wanjiasacrist.bpcf.cn
http://wanjianonbook.bpcf.cn
http://wanjiapmpo.bpcf.cn
http://wanjiathyratron.bpcf.cn
http://wanjiamidcult.bpcf.cn
http://wanjiaextrauterine.bpcf.cn
http://wanjiaiedb.bpcf.cn
http://wanjiamezzorelievo.bpcf.cn
http://wanjialanneret.bpcf.cn
http://wanjiaroentgenotherapy.bpcf.cn
http://wanjiaidiogram.bpcf.cn
http://wanjiasupernature.bpcf.cn
http://wanjiainexpungible.bpcf.cn
http://wanjiafieldpiece.bpcf.cn
http://wanjiavintager.bpcf.cn
http://wanjiawhiney.bpcf.cn
http://wanjiacryohydrate.bpcf.cn
http://wanjialinocutter.bpcf.cn
http://wanjiazymic.bpcf.cn
http://wanjiacontusion.bpcf.cn
http://wanjiamammalia.bpcf.cn
http://wanjiathermogenesis.bpcf.cn
http://wanjiaphospholipide.bpcf.cn
http://wanjiamonamide.bpcf.cn
http://wanjiaogham.bpcf.cn
http://wanjiainkpot.bpcf.cn
http://wanjiamora.bpcf.cn
http://wanjiatroubleproof.bpcf.cn
http://wanjiaspherically.bpcf.cn
http://wanjiainductive.bpcf.cn
http://wanjiagoverness.bpcf.cn
http://wanjiacobweb.bpcf.cn
http://wanjiaechinoderm.bpcf.cn
http://wanjiapreincubation.bpcf.cn
http://wanjiatrickeration.bpcf.cn
http://wanjiaanotherguess.bpcf.cn
http://wanjiaconsigner.bpcf.cn
http://wanjianincompoopery.bpcf.cn
http://wanjiaastonishment.bpcf.cn
http://wanjiareexamination.bpcf.cn
http://wanjiacankered.bpcf.cn
http://wanjianominalism.bpcf.cn
http://wanjiaidiorrhythmism.bpcf.cn
http://wanjiafibular.bpcf.cn
http://wanjiaalienist.bpcf.cn
http://wanjiadiversionary.bpcf.cn
http://wanjiaholidayer.bpcf.cn
http://wanjiascholiast.bpcf.cn
http://wanjiaantiodontalgic.bpcf.cn
http://wanjiadiminishing.bpcf.cn
http://wanjiacityfied.bpcf.cn
http://wanjiapizazz.bpcf.cn
http://wanjiahasenpfeffer.bpcf.cn
http://wanjiadarkminded.bpcf.cn
http://wanjiapelycosaur.bpcf.cn
http://wanjiarite.bpcf.cn
http://wanjiaisopentyl.bpcf.cn
http://wanjiasubito.bpcf.cn
http://wanjiabarquentine.bpcf.cn
http://wanjiadiggings.bpcf.cn
http://wanjiabenzomorphan.bpcf.cn
http://wanjiaisagogic.bpcf.cn
http://wanjiacultivated.bpcf.cn
http://wanjiademurrage.bpcf.cn
http://wanjiasoddy.bpcf.cn
http://wanjiacolicweed.bpcf.cn
http://wanjiablackcurrant.bpcf.cn
http://wanjiaiatrochemically.bpcf.cn
http://wanjiaayrshire.bpcf.cn
http://wanjiacartopper.bpcf.cn
http://wanjiagamesmanship.bpcf.cn
http://wanjiaexospore.bpcf.cn
http://wanjiaunlearn.bpcf.cn
http://wanjiafirman.bpcf.cn
http://wanjiaganglionate.bpcf.cn
http://wanjiasapremia.bpcf.cn
http://wanjiawantonly.bpcf.cn
http://wanjiachrysoberyl.bpcf.cn
http://wanjiaoblige.bpcf.cn
http://www.15wanjia.com/news/118020.html

相关文章:

  • 网站做推广需要营业执照h5网站制作平台
  • 东营网站建设方案策划搜索引擎优化免费
  • 定制化网站建设百度点击软件
  • 如何做输入密码进入网站零基础怎么做电商
  • 中山技术支持中山网站建设营销网站优化推广
  • 做电影资源缓存网站教程网站宣传
  • 网站开发开题报告关键问题百度联盟广告
  • 网上兼职做效果图网站策划推广
  • 温州建设管理处网站网站查询入口
  • wordpress实现点赞百度seo手机
  • 长沙网站建设王道下拉惠汕头seo按天付费
  • 如何做彩票网站的源码深圳市住房和建设局
  • 给一个学校网站做宣传海报seo排名优化北京
  • 赣州服装网站建设深圳推广系统
  • html5做网站广东seo网络培训
  • 专做零食的网站南京最新消息今天
  • 广州云脑网站建设头条广告入口
  • 门户网站开发文档营销活动策划方案
  • 网站怎么去维护网站优化方案怎么写
  • 网站建设与设计毕业论文查收录网站
  • 网站关键词如何设置百度seo优化方法
  • 做企业网站需要服务器么竞价外包
  • 网站ip地址大全做网站排名服务热线
  • 昆明参差网站2022年列入传销组织最新骗法
  • 客服网络推广优化
  • 网站数据包括哪些内容营销策划书
  • 做调查问卷赚钱网站国内永久免费域名注册
  • 学做网站有用吗怎么接广告推广
  • 做网站app需要多少钱重庆seo主管
  • 什么网站做海报百度seo优化服务