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

做网站需要自己上传产品吗wordpress可以做淘宝客

做网站需要自己上传产品吗,wordpress可以做淘宝客,永兴网站建设报价,东莞比较好的设计公司由于子项目比较多#xff0c;子项目都是通过嵌套的方式实现的。就会导致子页面加载比较慢#xff0c;影响客户体验 实现思路#xff08;AI搜的--!#xff09;: 1、通过spring boot缓存实现静态资源缓存 2、在gateway过滤器#xff0c;对静态资源进行缓存 直接上代码子项目都是通过嵌套的方式实现的。就会导致子页面加载比较慢影响客户体验 实现思路AI搜的--!: 1、通过spring boot缓存实现静态资源缓存 2、在gateway过滤器对静态资源进行缓存 直接上代码 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-cache/artifactId /dependency package com.xxx.filter;import lombok.extern.slf4j.Slf4j; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.support.SimpleValueWrapper; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.core.Ordered; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono;import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;/*** author Wang* 创建时间: 2023/11/15 10:19* 功能描述静态资源缓存*/ Slf4j Component public class StaticResourceFilter implements GlobalFilter, Ordered {private static final String STATIC_RESOURCE_PATTERN \\.(html|css|js|png|jpg|jpeg|gif|woff2|woff)$;private final WebClient webClient;private final CacheManager cacheManager;ListString synchronizedList Collections.synchronizedList(new ArrayList());public StaticResourceFilter(WebClient webClient, CacheManager cacheManager) {this.webClient webClient;this.cacheManager cacheManager;}Overridepublic MonoVoid filter(ServerWebExchange exchange, GatewayFilterChain chain) {ServerHttpRequest request exchange.getRequest();URI uriInfo request.getURI();String staticResourcePath getUrl(uriInfo);if (isStaticResource(staticResourcePath) !synchronizedList.contains(staticResourcePath)) {//Route route exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR);String cacheKey request.getURI().toString();Cache cache cacheManager.getCache(staticResources);// 尝试从缓存中获取静态资源Object cachedResource cache.get(cacheKey);if (cachedResource ! null) {if (cachedResource instanceof SimpleValueWrapper) {cachedResource ((SimpleValueWrapper) cachedResource).get();}// 如果缓存中存在直接返回缓存的资源ServerHttpResponse response exchange.getResponse();HttpHeaders headers response.getHeaders();String fileSuffix staticResourcePath.replaceAll(.*(\\.[a-zA-Z0-9])$, $1);// 根据文件后缀设置MIME类型switch (fileSuffix) {case .html:headers.setContentType(MediaType.TEXT_HTML);break;case .js:headers.set(HttpHeaders.CONTENT_TYPE, application/javascript);break;case .css:headers.set(HttpHeaders.CONTENT_TYPE, text/css);break;case .png:headers.setContentType(MediaType.IMAGE_PNG);break;case .jpg:case .jpeg:headers.setContentType(MediaType.IMAGE_JPEG);break;case .woff:headers.set(HttpHeaders.CONTENT_TYPE, application/font-woff);break;case .woff2:headers.set(HttpHeaders.CONTENT_TYPE, application/font-woff2);break;case .ttf:headers.set(HttpHeaders.CONTENT_TYPE, application/x-font-ttf);break;case .eot:headers.set(HttpHeaders.CONTENT_TYPE, application/vnd.ms-fontobject);break;default:headers.setContentType(MediaType.ALL);break;}// 这里假设缓存的内容是字节数组您可以根据实际情况进行调整DataBuffer dataBuffer response.bufferFactory().wrap((byte[]) cachedResource);return response.writeWith(Mono.just(dataBuffer));}// 如果缓存不存在则继续请求下游服务获取资源并将其缓存起来return chain.filter(exchange).then(Mono.fromRunnable(() - {getResourceFromDownstream(staticResourcePath, cacheKey, cache);}));}// 继续处理其他过滤器或请求return chain.filter(exchange);}Overridepublic int getOrder() {return Ordered.HIGHEST_PRECEDENCE;}/*** 根据请求路径判断是否为静态资源请求** param staticResourcePath 请求路径*/private boolean isStaticResource(String staticResourcePath) {Pattern pattern Pattern.compile(STATIC_RESOURCE_PATTERN);Matcher matcher pattern.matcher(staticResourcePath);return matcher.find();}/*** 请求下游服务静态资源的方法这里只是一个示例您需要根据实际情况实现此方法** param cache 缓存* param staticResourcePath URL* param cacheKey 缓存Key*/private void getResourceFromDownstream(String staticResourcePath, String cacheKey, Cache cache) {synchronizedList.add(staticResourcePath);Monobyte[] mono webClient.get().uri(staticResourcePath).retrieve().bodyToMono(byte[].class);// 处理响应数据mono.subscribe(res - {synchronizedList.remove(staticResourcePath);cache.put(cacheKey, res);}, error - {log.error(请求下游服务静态资源失败{}\n错误详情:{}, staticResourcePath, error.toString());});}/*** 获取静态资源地址** param uri uri* return 静态资源地址*/private String getUrl(URI uri) {String path uri.getPath();String host uri.getHost();int port uri.getPort();// 下游服务的地址是String downstreamUrl String.format(http://%s:%s%s, host, port, path);return downstreamUrl;} }
http://www.zqtcl.cn/news/697982/

相关文章:

  • 求个网站没封的2021网站建设初步课程介绍
  • 沈阳网站前端网站建栏目建那些
  • 经典网站案例江苏省建设厅官网
  • 公司建设网站需要多少钱重庆房产网站建设
  • 鹤岗市建设局网站可信网站认证有用吗
  • 网站注册的账号怎么注销如何百度推广
  • 用wordpress制作网站模板阿里云网站建设合作
  • 金华建设公司网站宝武马钢集团公司招聘网站
  • 万州网站制作公司阳江市网站建设
  • 下载建设网站软件投资公司注册资金多少
  • 如何创建一个论坛网站免费域名解析平台
  • 国外经典手机网站设计单位做网站有哪些
  • 网站备案 优帮云百度提交入口网址截图
  • 广州五羊建设官方网站富阳区住房和城乡建设局网站
  • 网站代理怎么做的wordpress有什么缺点
  • 哪些网站可以做免费外贸Wordpress首图自动切换
  • 建网站几个按钮公司黄页企业名录在哪里查
  • 网站建设类外文翻译游戏开科技软件免费
  • 黄山家居网站建设怎么样济南在线制作网站
  • 东莞电子产品网站建设营销型网站推广方式的论文
  • 如何寻找做网站的客户聚名网查询
  • 甘肃制作网站凡科快图官网登录入口在线
  • discuz网站建设教学视频教程哪些大型网站有做互联网金融
  • jquery动画特效网站物流网站前端模板下载
  • 上海集团网站建设网站都是用什么语言写的
  • 地铁公司招聘信息网站网站推广页面 英语
  • 廊坊做网站的企业哪家好做网站app价格多少钱
  • wap网站制作当阳网站建设电话
  • 服装电子商务网站建设3000字中装建设有限公司
  • 河南卓越建设工程有限公司网站怎么做垂直门户网站