当前位置: 首页> 科技> 互联网 > 泰安网红金火火_软件开发外包有前途吗_淘宝客推广平台_760关键词排名查询

泰安网红金火火_软件开发外包有前途吗_淘宝客推广平台_760关键词排名查询

时间:2025/7/10 17:30:16来源:https://blog.csdn.net/m0_65152767/article/details/142369619 浏览次数:0次
泰安网红金火火_软件开发外包有前途吗_淘宝客推广平台_760关键词排名查询

文章目录

  • 1、缓存穿透
  • 2、缓存空对象
  • 3、AlbumInfoApiController --》getAlbumInfo()
  • 4、AlbumInfoServiceImpl --》getAlbumInfo()
  • 5、RedisConstant
  • 6、请求缓存不存在的数据

1、缓存穿透

缓存穿透带有恶意性,强调不存在的数据。
在这里插入图片描述

2、缓存空对象

在这里插入图片描述

3、AlbumInfoApiController --》getAlbumInfo()

	@GetMapping("getAlbumInfo/{albumId}")public Result<AlbumInfo> getAlbumInfo(@PathVariable("albumId") Long albumId) {
//		try {
//			Thread.sleep(20);
//		} catch (InterruptedException e) {
//			throw new RuntimeException(e);
//		}AlbumInfo albumInfo = this.albumInfoService.getAlbumInfo(albumId);return Result.ok(albumInfo);}

4、AlbumInfoServiceImpl --》getAlbumInfo()

    public AlbumInfo getAlbumInfo(Long albumId) {// 1.先查询缓存,如果命中则直接返回AlbumInfo albumInfo = (AlbumInfo) this.redisTemplate.opsForValue().get(RedisConstant.ALBUM_INFO_PREFIX + albumId);if (albumInfo != null) {return albumInfo;}// 查询专辑albumInfo = this.getById(albumId);if (albumInfo != null) {// 根据专辑查询专辑标签值List<AlbumAttributeValue> albumAttributeValues = this.attributeValueMapper.selectList(new LambdaQueryWrapper<AlbumAttributeValue>().eq(AlbumAttributeValue::getAlbumId, albumId));albumInfo.setAlbumAttributeValueVoList(albumAttributeValues);}// 2.放入缓存if (albumInfo == null) {// 为了防止缓存穿透:数据即使为空也缓存,只是缓存时间不宜太长。this.redisTemplate.opsForValue().set(RedisConstant.ALBUM_INFO_PREFIX + albumId, albumInfo, RedisConstant.ALBUM_TEMPORARY_TIMEOUT, TimeUnit.SECONDS);}else {this.redisTemplate.opsForValue().set(RedisConstant.ALBUM_INFO_PREFIX + albumId, albumInfo, RedisConstant.CACHE_TIMEOUT, TimeUnit.SECONDS);}return albumInfo;}

在这里插入图片描述

5、RedisConstant

    public static final String ALBUM_INFO_PREFIX = "album:info:";// 商品如果在数据库中不存在那么会缓存一个空对象进去,但是这个对象是没有用的,所以这个对象的过期时间应该不能太长,// 如果太长会占用内存。// 定义变量,记录空对象的缓存过期时间public static final long ALBUM_TEMPORARY_TIMEOUT = 10 * 60;public static final long CACHE_TIMEOUT = 24 * 60 * 60;

6、请求缓存不存在的数据

http://127.0.0.1:8500/api/album/albumInfo/getAlbumInfo/9800

在这里插入图片描述
在这里插入图片描述

关键字:泰安网红金火火_软件开发外包有前途吗_淘宝客推广平台_760关键词排名查询

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: