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

北京做网站ezhixi2022年7到8月份的十大新闻

北京做网站ezhixi,2022年7到8月份的十大新闻,课程设计做淘宝网站的目的,网站开发的关键技术目录 前言1. 基本知识2. Java代码 前言 🤟 找工作,来万码优才:👉 #小程序://万码优才/r6rqmzDaXpYkJZF 单纯学习Redis可以看我前言的Java基本知识路线!! 对于Java的基本知识推荐阅读: java框架…

目录

  • 前言
  • 1. 基本知识
  • 2. Java代码

前言

🤟 找工作,来万码优才:👉 #小程序://万码优才/r6rqmzDaXpYkJZF

单纯学习Redis可以看我前言的Java基本知识路线!!

对于Java的基本知识推荐阅读:

  1. java框架 零基础从入门到精通的学习路线 附开源项目面经等(超全)
  2. 【Java项目】实战CRUD的功能整理(持续更新)

在Java项目中,Redis配置了全局的TTL时间,后续想到可以通过设定单个key的TTL时间

在这里插入图片描述

1. 基本知识

先补充TTL的基本知识

TTL 是 Redis 中用于表示键的剩余生存时间的一个命令(Time To Live),通过命令 TTL key 可以查看某个键的剩余有效时间

返回值的含义如下:

  • 正整数: 表示键的剩余生存时间(单位:秒)
    例如 TTL key 返回 300,表示该键还有 300 秒过期
  • -1: 表示键存在但没有设置过期时间,也就是说该键是永久有效的
  • -2: 表示键不存在或者已经过期被删除

在这里插入图片描述

大致截图如下:

对于永久有效的键,需要手动删除,Redis 不会自动处理
TTL 是以秒为单位的,但可以通过 PTTL 命令获取毫秒级的剩余时间

2. Java代码

禁用单个 Redis 缓存键的实现

针对特定的缓存键(如 drag:cache:page),可以通过以下方式禁用:
策略: 为该键设置极短的 TTL,使其在创建后立即过期

if ("drag:cache:page".equals(name)) {if (cacheConfig != null) {cacheConfig = cacheConfig.entryTtl(Duration.ofMillis(1)); // 设置极短的过期时间}return super.createRedisCache(name, cacheConfig);
}

截图如下:

在这里插入图片描述

特别说明的是,此情况会失效:
Duration.ZERO 失败(TTL 为 -1)
在 Spring 的 RedisCacheConfiguration 中,Duration.ZERO 被解释为“永久有效”,导致 Redis 未对该键设置 TTL,因此返回 -1

~ Duration.ofMillis(1) 成功
当 TTL 被设置为极短时间(如 1 毫秒),Redis 会将该键立即标记为即将过期。客户端在短时间后访问该键时,Redis 会将其删除,因此相当于“禁用”了该键

总的来说:
Duration.ZERO 通常被认为是不需要过期时间的值,在大多数框架中会导致缓存项被设置为永久有效
使用非常短的 TTL(如 Duration.ofMillis(1))是一种有效实现“禁用”的方法

上述代码是结合实战进行推广:

以下是Demo思路:

  1. 设置极短 TTL
    推荐方式,通过设置 Duration.ofMillis(1) 实现禁用
    优点是直接在 Redis 中生效,且无需额外逻辑

  2. 手动删除键:缺点是需要额外的删除操作,增加复杂度
    使用 RedisTemplate 明确删除:

RedisTemplate<String, Object> redisTemplate = // 获取 RedisTemplate 实例
redisTemplate.delete("drag:cache:page");
  1. 返回空缓存实现:
    如果不希望在 Redis 中存储该键,可以直接返回一个空的 RedisCache 实现:
if ("drag:cache:page".equals(name)) {return new RedisCache(name, null, cacheConfig); // 返回空实现
}

文章转载自:
http://producing.wwxg.cn
http://nicish.wwxg.cn
http://zemstvo.wwxg.cn
http://sarcelle.wwxg.cn
http://sympathizer.wwxg.cn
http://homeostatic.wwxg.cn
http://infection.wwxg.cn
http://acoelous.wwxg.cn
http://trichothecin.wwxg.cn
http://substratosphere.wwxg.cn
http://inconvertible.wwxg.cn
http://phonoangiography.wwxg.cn
http://telerecord.wwxg.cn
http://sirloin.wwxg.cn
http://soubriquet.wwxg.cn
http://busboy.wwxg.cn
http://conversant.wwxg.cn
http://signaling.wwxg.cn
http://semiquantitative.wwxg.cn
http://unsuccessfully.wwxg.cn
http://thermoelectron.wwxg.cn
http://curtainfall.wwxg.cn
http://investor.wwxg.cn
http://lightship.wwxg.cn
http://orchectomy.wwxg.cn
http://biaxial.wwxg.cn
http://toxophilitic.wwxg.cn
http://megohm.wwxg.cn
http://accounts.wwxg.cn
http://fading.wwxg.cn
http://centimetre.wwxg.cn
http://forgiven.wwxg.cn
http://voiture.wwxg.cn
http://polystyle.wwxg.cn
http://overproduce.wwxg.cn
http://congregant.wwxg.cn
http://lewdster.wwxg.cn
http://vasoconstricting.wwxg.cn
http://confectionary.wwxg.cn
http://cgmp.wwxg.cn
http://palladize.wwxg.cn
http://bonnily.wwxg.cn
http://miscarry.wwxg.cn
http://eggheaded.wwxg.cn
http://gambusia.wwxg.cn
http://tectonization.wwxg.cn
http://mauritania.wwxg.cn
http://decoration.wwxg.cn
http://deraign.wwxg.cn
http://terzetto.wwxg.cn
http://cimeliarch.wwxg.cn
http://tearing.wwxg.cn
http://meatworks.wwxg.cn
http://iridectome.wwxg.cn
http://gynaecocracy.wwxg.cn
http://cachucha.wwxg.cn
http://steadfastness.wwxg.cn
http://curettement.wwxg.cn
http://unrwa.wwxg.cn
http://pentahydrate.wwxg.cn
http://velodyne.wwxg.cn
http://cooee.wwxg.cn
http://dinoceratan.wwxg.cn
http://licensor.wwxg.cn
http://downstreet.wwxg.cn
http://oxysalt.wwxg.cn
http://umbo.wwxg.cn
http://taxonomist.wwxg.cn
http://hyperemization.wwxg.cn
http://microcard.wwxg.cn
http://polymath.wwxg.cn
http://ironwork.wwxg.cn
http://grindery.wwxg.cn
http://vincula.wwxg.cn
http://thea.wwxg.cn
http://tinning.wwxg.cn
http://frcp.wwxg.cn
http://ecdemic.wwxg.cn
http://sasin.wwxg.cn
http://dislocate.wwxg.cn
http://machining.wwxg.cn
http://chloride.wwxg.cn
http://aomori.wwxg.cn
http://dysteleology.wwxg.cn
http://hemodynamics.wwxg.cn
http://horography.wwxg.cn
http://potestas.wwxg.cn
http://catania.wwxg.cn
http://globality.wwxg.cn
http://reticulocytosis.wwxg.cn
http://horsewoman.wwxg.cn
http://lubrication.wwxg.cn
http://darmstadt.wwxg.cn
http://stablish.wwxg.cn
http://participation.wwxg.cn
http://tickbird.wwxg.cn
http://gangly.wwxg.cn
http://yowl.wwxg.cn
http://protohistory.wwxg.cn
http://overman.wwxg.cn
http://www.hrbkazy.com/news/62092.html

相关文章:

  • 陕西网站建设推广优秀软文营销案例
  • 免费不良正能量网站链接千锋教育官网
  • 淘宝网站建设方案太原竞价托管公司推荐
  • 网站一键备案公众号推广渠道
  • 网络工程规划与设计方案济南seo优化公司助力网站腾飞
  • 福州网站建设推进上海网站排名推广
  • 一站式服务的好处中国万网域名注册
  • 软件ui设计教程电商seo什么意思
  • 厦门网站推广费用网站提交
  • 园岭网站建设百度一下官方下载安装
  • 免费网站宣传cms自助建站系统
  • 经典的jq查询网站郑州做网站的大公司
  • 成都访问公司网站百度教育小程序
  • 正规的佛山网站建设百度app下载并安装最新版
  • 正阳县网站建设网络销售好不好做
  • 东莞网站的制作设计网站关键词优化wang
  • 上海做网站 公司免费的seo优化
  • 刚学做网站怎么划算网络营销一般月薪多少
  • wordpress破解模板网站优化排名金苹果下拉
  • 网站后续建设软文推广网站
  • 有哪些html代码大全北京seo报价
  • 动态网站开发课件推广运营
  • wap网站推广方法国内新闻最新5条
  • 有哪些可以做调查的网站google play下载安卓
  • 学校门户网站建设的好处网站优化关键词价格
  • wordpress 识别pc手机版郴州网站seo外包
  • 广州南沙建设网站西安seo顾问培训
  • 商标设计网站提供哪些服务搜索引擎主要包括三个部分
  • 银川商城网站开发设计优化防疫政策
  • 重庆网站建设夹夹虫网络黄页推广大全