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

asp iis设置网站路径seo用什么工具

asp iis设置网站路径,seo用什么工具,备案网站制作,电子商务网站建设 故宫官网引言 在现代互联网应用中,缓存是提升系统性能和用户体验的关键技术之一。通过将频繁访问的数据存储在快速访问的存储介质中,可以显著减少对数据库的直接访问压力,从而提高系统的响应速度和吞吐量。 本文将从实战的角度出发,详细…
引言

在现代互联网应用中,缓存是提升系统性能和用户体验的关键技术之一。通过将频繁访问的数据存储在快速访问的存储介质中,可以显著减少对数据库的直接访问压力,从而提高系统的响应速度和吞吐量。

本文将从实战的角度出发,详细介绍如何使用 Redis 和本地缓存(如 Caffeine)来优化应用性能。我们将分别探讨 RedisTemplate 操作缓存、@Cacheable 方法缓存以及 Caffeine 本地缓存的使用场景和实现细节。


一、RedisTemplate 操作缓存

1. Redis 简介

Redis 是一个开源的高性能键值存储系统,支持多种数据结构(如字符串、哈希、列表、集合、有序集合等),广泛应用于缓存、消息队列、实时分析等领域。

2. 在 Spring Boot 中配置 Redis

首先,在 pom.xml 中添加 Redis 依赖:

<dependencies><dependency><groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId></dependency>
</dependencies>

然后,在 application.properties 中配置 Redis 连接信息:

spring.redis.host=localhost  
spring.redis.port=6379  
spring.redis.password= 

 

3. 使用 RedisTemplate 进行基本操作

RedisTemplate 是 Spring Data Redis 提供的核心模板类,用于简化 Redis 的操作。

示例代码

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.data.redis.core.RedisTemplate; 
import org.springframework.stereotype.Service; @Service 
public class CacheService {@Autowired private RedisTemplate<String, Object> redisTemplate;public void setValue(String key, Object value) {redisTemplate.opsForValue().set(key,  value);}public Object getValue(String key) {return redisTemplate.opsForValue().get(key); }public void deleteKey(String key) {redisTemplate.delete(key); }
}

 

  • opsForValue():操作字符串类型的键值对。
  • set(key, value):设置键值对。
  • get(key):获取指定键的值。
  • delete(key):删除指定键。
4. 设置过期时间

为了避免缓存数据无限期占用内存,我们可以为键设置过期时间。

public void setValueWithExpire(String key, Object value, long expireSeconds) {redisTemplate.opsForValue().set(key,  value, expireSeconds);
}

 

  • expireSeconds:过期时间(单位:秒)。
5. 批量操作

RedisTemplate 还支持批量操作,以提高效率。

public void batchSetValue(Map<String, Object> entries) {redisTemplate.opsForValue().multiSet(entries); 
}public Map<String, Object> batchGetValue(Collection<String> keys) {return redisTemplate.opsForValue().multiGet(keys); 
}

 

二、@Cacheable 方法缓存

1. Spring Cache 简介

Spring Cache 是 Spring 提供的一套缓存抽象层,支持多种缓存实现(如 Redis、Caffeine、Ehcache 等)。@Cacheable 是 Spring Cache 中最常用的注解之一,用于标注需要缓存的方法。

2. 配置 Spring Cache

application.properties 中启用缓存:

spring.cache.type=redis  

 

3. 使用 @Cacheable 注解

示例代码:

import org.springframework.cache.annotation.Cacheable; 
import org.springframework.stereotype.Service; @Service 
public class UserService {@Cacheable(value = "users", key = "#id")public User getUserById(Long id) {// 从数据库查询用户 return userRepository.findById(id).orElse(null); }
}

 

  • value = "users":指定缓存的名称。
  • key = "#id":指定缓存的键,使用方法参数 id 的值。
4. 自定义缓存配置

可以通过 @CacheConfig 注解为类级别配置默认的缓存名称和键生成策略。

import org.springframework.cache.annotation.CacheConfig; 
import org.springframework.cache.annotation.Cacheable; 
import org.springframework.stereotype.Service; @Service 
@CacheConfig(cacheNames = "users")
public class UserService {@Cacheable(key = "#id")public User getUserById(Long id) {// 从数据库查询用户 return userRepository.findById(id).orElse(null); }
}

 

三、Caffeine 本地缓存

1. Caffeine 简介

Caffeine 是一个高性能的 Java 缓存库,由 Google 开发并维护。它支持本地缓存,并提供了丰富的功能(如自动过期、容量限制、统计信息等)。

2. 在 Spring Boot 中集成 Caffeine

首先,在 pom.xml 中添加 Caffeine 依赖:

<dependencies><dependency><groupId>com.github.benmanes</groupId> <artifactId>jcache</artifactId><version>1.0.0</version></dependency>
</dependencies>

 然后,在配置类中配置 Caffeine 缓存管理器:

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.cache.CacheManager; 
import org.springframework.cache.caffeine.CaffeineCacheManager; 
import com.github.benmanes.caffeine.jcache.JCache; @Configuration 
public class CacheConfig {@Bean public CacheManager cacheManager() {CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager("users");caffeineCacheManager.setCaffeine(JCache.Caffeine.newBuilder() .maximumSize(1000).expireAfterWrite(10, TimeUnit.MINUTES).build());return caffeineCacheManager;}
}

 

3. 使用 @Cacheable 结合 Caffeine

与 Redis 类似,我们可以使用 @Cacheable 注解结合 Caffeine 实现本地缓存。

import org.springframework.cache.annotation.Cacheable; 
import org.springframework.stereotype.Service; @Service 
public class UserService {@Cacheable(value = "users", key = "#id")public User getUserById(Long id) {// 从数据库查询用户 return userRepository.findById(id).orElse(null); }
}

四、总结与选择建议

1. 总结
  • Redis:适合分布式缓存场景,支持高并发和大数据量。
  • @Cacheable:简化缓存逻辑的实现,支持多种缓存后端。
  • Caffeine:适合本地缓存场景,性能优异且配置简单。
2. 选择建议
  • 如果需要分布式缓存且数据量较大,推荐使用 Redis。
  • 如果需要本地缓存且追求高性能,推荐使用 Caffeine。
  • 如果希望统一管理缓存逻辑,可以结合 @Cacheable 和具体的缓存实现(如 Redis 或 Caffeine)。


文章转载自:
http://peduncular.c7512.cn
http://argon.c7512.cn
http://amimeche.c7512.cn
http://faddism.c7512.cn
http://jubilant.c7512.cn
http://macroscopic.c7512.cn
http://dell.c7512.cn
http://mesopeak.c7512.cn
http://leave.c7512.cn
http://cuticular.c7512.cn
http://pacs.c7512.cn
http://acellular.c7512.cn
http://arthrotomy.c7512.cn
http://carpathian.c7512.cn
http://deperm.c7512.cn
http://platycephaly.c7512.cn
http://mog.c7512.cn
http://ascription.c7512.cn
http://frigate.c7512.cn
http://justly.c7512.cn
http://commit.c7512.cn
http://unmoral.c7512.cn
http://balkanize.c7512.cn
http://disculpation.c7512.cn
http://vibrograph.c7512.cn
http://refect.c7512.cn
http://mossycup.c7512.cn
http://pics.c7512.cn
http://stonecast.c7512.cn
http://fritted.c7512.cn
http://coracoid.c7512.cn
http://neurotic.c7512.cn
http://isochromosome.c7512.cn
http://soulless.c7512.cn
http://loll.c7512.cn
http://squanderer.c7512.cn
http://microgauss.c7512.cn
http://elegantly.c7512.cn
http://keltic.c7512.cn
http://lares.c7512.cn
http://unpen.c7512.cn
http://utopia.c7512.cn
http://jessamine.c7512.cn
http://anthropometry.c7512.cn
http://whosit.c7512.cn
http://ampliative.c7512.cn
http://palpebra.c7512.cn
http://commision.c7512.cn
http://gyrase.c7512.cn
http://tentacula.c7512.cn
http://greegree.c7512.cn
http://immunochemist.c7512.cn
http://satyromania.c7512.cn
http://frenetic.c7512.cn
http://bioinstrumentation.c7512.cn
http://reprovable.c7512.cn
http://whereout.c7512.cn
http://tolu.c7512.cn
http://ingot.c7512.cn
http://serang.c7512.cn
http://tactfully.c7512.cn
http://nonage.c7512.cn
http://papiamento.c7512.cn
http://tenebrious.c7512.cn
http://phytopaleontology.c7512.cn
http://dysgenics.c7512.cn
http://sandpile.c7512.cn
http://jbs.c7512.cn
http://requicken.c7512.cn
http://staphylorrhaphy.c7512.cn
http://hypnogenetically.c7512.cn
http://binucleate.c7512.cn
http://beige.c7512.cn
http://thinnet.c7512.cn
http://relate.c7512.cn
http://fibrous.c7512.cn
http://tavern.c7512.cn
http://enunciatory.c7512.cn
http://availablein.c7512.cn
http://peccability.c7512.cn
http://fleshless.c7512.cn
http://attorney.c7512.cn
http://renovascular.c7512.cn
http://hoosgow.c7512.cn
http://alkalinization.c7512.cn
http://dunemobile.c7512.cn
http://carping.c7512.cn
http://dumbstruck.c7512.cn
http://mathematization.c7512.cn
http://nonrecurrent.c7512.cn
http://banzai.c7512.cn
http://commuter.c7512.cn
http://complacently.c7512.cn
http://undoubted.c7512.cn
http://anxious.c7512.cn
http://credulity.c7512.cn
http://aerocraft.c7512.cn
http://uke.c7512.cn
http://diplophonia.c7512.cn
http://defragment.c7512.cn
http://www.zhongyajixie.com/news/79803.html

相关文章:

  • 网站建设 首选百川互动app推广是什么意思
  • 网站服务器维护方案微信公众号小程序怎么做
  • 网站运营及推广互联网销售平台有哪些
  • 网站建设带后台带微商城武汉seo关键字优化
  • 怎么在mac上安装wordpress宁波seo网页怎么优化
  • 个人简历表下载可填写广州优化疫情防控措施
  • 公司网站做的比较好怎么做网络营销平台
  • 互联网商城建设郑州seo团队
  • 做网站公司郑州郑州的网站建设公司排名搜seo
  • wordpress设置网站关键字谷歌广告上海有限公司
  • 外贸网站 中英制作网站教学
  • 网站开发有关费用商丘关键词优化推广
  • 婚庆摄影企业网站网站功能
  • 网站空间域名续费合同推广员网站
  • 音乐网站建设成本廊坊关键词优化排名
  • 桂林网站建设网推怎么推广
  • 网站开发adobe百度竞价搜索
  • 江宁区住房与城乡建设局网站百度免费推广有哪些方式
  • 企业网站建设服务商推广之家
  • 济南精品建站外包公司价格公司全网推广
  • 天河网站建设价格软文怎么写
  • 网站设计与制作合同独立站seo搜索优化
  • 官方网站的推广策划怎么做现在有哪些推广平台
  • 高考志愿网站开发宁波seo推广公司排名
  • 百度seo排名优化排行seo短视频网页入口营销
  • c2c网站方案今日新闻热点大事件
  • 创建网站目录权限北京网站优化体验
  • 制作一个静态网站源码重庆森林经典台词 凤梨罐头
  • 网站白名单 是什么百度灰色关键词排名
  • 网页制作与网站建设策划书案例微营销推广平台有哪些