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

怎么查寻一个网站做的竞价市场调研方案

怎么查寻一个网站做的竞价,市场调研方案,大连是谁建设的,lnmp wordpress ssl本文将介绍如何在Spring Boot应用中实现基于请求参数MD5的缓存键,以及其他常见的缓存方式。通过实际代码示例,展示如何应用这些技术优化系统性能。 1. 引入必要的依赖 首先,在Spring Boot项目中引入缓存相关的依赖。修改pom.xml文件&#x…

本文将介绍如何在Spring Boot应用中实现基于请求参数MD5的缓存键,以及其他常见的缓存方式。通过实际代码示例,展示如何应用这些技术优化系统性能。

1. 引入必要的依赖

首先,在Spring Boot项目中引入缓存相关的依赖。修改pom.xml文件,添加如下依赖:

<dependencies><!-- Spring Boot Starter Web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Spring Boot Starter Cache --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId></dependency><!-- Optional: Spring Boot Starter Data Redis for Redis Cache --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>
</dependencies>

2. 配置缓存

application.properties中进行缓存配置。这里以内存缓存(如ConcurrentMapCacheManager)为例:

spring.cache.type=simple

如果使用Redis作为缓存,可以进行如下配置:

spring.cache.type=redis
spring.redis.host=localhost
spring.redis.port=6379

3. 启用缓存支持

在Spring Boot应用的主类或配置类上添加@EnableCaching注解:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;@SpringBootApplication
@EnableCaching
public class CacheApplication {public static void main(String[] args) {SpringApplication.run(CacheApplication.class, args);}
}

4. 计算请求参数的MD5作为缓存键

创建一个自定义缓存键生成器,计算请求参数的MD5值并作为缓存键:

import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;@Component("customKeyGenerator")
public class CustomKeyGenerator implements KeyGenerator {@Overridepublic Object generate(Object target, Method method, Object... params) {try {// 将请求参数按一定顺序组合成字符串String paramStr = Arrays.stream(params).map(Object::toString).reduce((a, b) -> a + "&" + b).orElse("");// 计算MD5值MessageDigest md = MessageDigest.getInstance("MD5");byte[] hash = md.digest(paramStr.getBytes(StandardCharsets.UTF_8));// 转换为32位的哈希值StringBuilder hexString = new StringBuilder();for (byte b : hash) {hexString.append(String.format("%02x", b));}return hexString.toString();} catch (NoSuchAlgorithmException e) {throw new RuntimeException(e);}}
}

5. 应用缓存注解

在服务层应用缓存注解,使用自定义的缓存键生成器:

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;@Service
public class MyService {@Cacheable(value = "myCache", keyGenerator = "customKeyGenerator")public String getData(String param1, String param2) {// 模拟耗时操作try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}return "Data from " + param1 + " and " + param2;}
}

6. 其他缓存方式

除了使用请求参数的MD5作为缓存键外,还可以采用其他缓存方式,如直接使用请求参数、组合多个参数等。示例如下:

6.1 直接使用请求参数作为缓存键


@Cacheable(value = "myCache", key = "#param1 + '-' + #param2")
public String getDataUsingParams(String param1, String param2) {// 模拟耗时操作try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}return "Data from " + param1 + " and " + param2;
}

6.2 组合多个参数作为缓存键

@Cacheable(value = "myCache", key = "T(String).valueOf(#param1).concat('-').concat(T(String).valueOf(#param2))")
public String getDataUsingCombinedParams(String param1, String param2) {// 模拟耗时操作try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}return "Data from " + param1 + " and " + param2;
}

http://www.15wanjia.com/news/45021.html

相关文章:

  • 一个网站建设初期的成本排名软件下载
  • 地方电商门户网站如何建设哈尔滨seo推广
  • 凡客陈年现状360优化大师app下载
  • 百度提交链接什么是搜索引擎优化的核心
  • 宁阳县住房和城乡建设局网站seo搜索引擎优化简历
  • 大型网站如何开发网页优化包括
  • 网站建设方案策划书ppt响应式网站模板的优势
  • 做网站静态和动态企业网站推广方法实验报告
  • 宜宾建设教育培训中心网站重庆seo点击工具
  • 广州哪里做公司网站号网络推广工具
  • 做婚礼效果图的网站有哪些嘉兴seo外包平台
  • 2022年8月国内重大新闻济南优化网络营销
  • 汤阴做网站上海最新政策
  • 呼和浩特网站制作如何屏蔽百度广告推广
  • 企业网站备案网址怎么查询搜索关键词
  • 个人中心页面抖音seo推广外包公司好做吗
  • 朋友圈营销推广seo推广seo技术培训
  • 广东购物网站建设推推蛙seo顾问
  • 西部数码网站建设教程爱网
  • 做外汇 虚拟网站百度优化排名软件
  • 网站开发费用怎么入账微信客户管理系统平台
  • 肥东县建设局网站百度百家号官网
  • 描述政府网站网站建设百度seo优化规则
  • the 7 wordpress主题教程seo在线诊断工具
  • 有模板怎么做网站想学编程去哪里找培训班
  • 龙华专业做网站公司微信公众号营销
  • 自己学习做网站6制作公司网站的公司
  • 培训网站大全百度seo关键词优化推荐
  • 网站栏目做ip地址访问限制网络营销建议
  • 导航类网站源码公司培训课程有哪些