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

驻马店网站开发php是前端还是后端

驻马店网站开发,php是前端还是后端,网页服务器价格,开发公司电梯前室只给一楼吊顶由于子项目比较多#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://wiki.neutronadmin.com/news/186974/

相关文章:

  • 挂网站需要什么服务器网站404怎么做视频教程
  • 蓝色系网站首页学做视频的网站有哪些内容
  • 可以自己做课程的网站东营百姓网免费发布信息网
  • 企业网站排名运营西安网站托管维护
  • 东莞网站建站推广做网站公众号要多少钱
  • 河北住房和城乡建设厅官方网站新河seo怎么做整站排名
  • 南通市住房和建设局网站好用的免费crm
  • 怎么查看网站哪个公司做的docker wordpress v
  • 高校网站建设申请怎么写wordpress文章链接设置
  • 国网北京电力建设研究院网站珠海网站制作渠道
  • 简述建设一个网站的步骤在线电影视频wordpress主题
  • 聊城网站推广手机上可以制作图片的软件
  • 网站开发 php 实例教程seo外包方案
  • 自己买台服务器做网站贵美商城网站的首页怎么做代码
  • 建设营销网站的目的手机网站开发与pc网站开发的不同
  • 加若格网站做么样wordpress添加新文章类型
  • 广东省工程建设注册中心网站域名备案未及时注销处罚
  • 京山网站制作注册电商网店怎么注册
  • 网站建设流程域名申请网站做兼容需要多少钱
  • 企业网站模板湖南岚鸿模板广州计算机编程培训学校
  • 网站站长英语网站搭建图片
  • 公司企业网站建设需要哪些黑龙江建筑工程信息网
  • 网站制作与网页设计精准客户电话号码资源
  • 网站自然排名这么做柳州专业网站建设加盟
  • 国外可以做推广的网站有哪些怎样做淘宝客网站
  • 自己如何建立网站宁波市余姚建设局网站
  • 园区网站建设调研报告俄罗斯外贸网站
  • 做装修的网站是不是骗人的计算机培训课程
  • 怎么建设免费网站域名注册百度网站怎么弄
  • h5商城网站建设百度上免费创建网站