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

淘宝联盟的网站怎么做的河北seo网络优化师

淘宝联盟的网站怎么做的,河北seo网络优化师,用手机搭建网站,wordpress怎么自动生成内链【图解秒杀系列】秒杀技术点——静态化 什么是静态化、静态化的作用如何实现静态化FreeMarker、Thymleaf处理流程问题 OpenResty Lualua_shared_dict & lua-resty-template处理流程具体操作 什么是静态化、静态化的作用 静态化就是指通过某种静态化技术,将原本…

【图解秒杀系列】秒杀技术点——静态化

  • 什么是静态化、静态化的作用
  • 如何实现静态化
    • FreeMarker、Thymleaf
      • 处理流程
      • 问题
    • OpenResty + Lua
      • lua_shared_dict & lua-resty-template
      • 处理流程
      • 具体操作

什么是静态化、静态化的作用

静态化就是指通过某种静态化技术,将原本需要动态渲染生成的HTML页面固定下来变成一个静态页面文件,后续请求该页面都直接返回该静态页面。

在这里插入图片描述

首先要有模板和数据,然后根据给定的模板和数据,通过模板引擎,就能生成对应的静态HTML文件。

在这里插入图片描述

生成的静态HTML页面,可以推到Nginx上缓存到Nginx本地。当用户请求访问对应的页面时,Nginx直接返回缓存在本地的静态页面,这样响应速度就大大提升。

在秒杀场景中,商品详情页就可以进行静态化处理,提升商品详情页的访问速度。

如何实现静态化

FreeMarker、Thymleaf

一种方式是通过FreeMarker、Thymleaf这种Java语言的模板引擎实现。

处理流程

FreeMarker、Thymleaf需要跑在一个Tomcat进程里面,当接收到请求时,通过Freemarker、Thymleaf等模板引擎技术,根据指定的模板和数据,生成静态HTML页面,返回客户端。

另外,我们可以监听MQ上的修改操作消息,当监听到有修改操作发生时,就在异步工程里面使用模板引擎生成静态HTML页面,然后推到Nginx上缓存到Nginx本地。

在这里插入图片描述

问题

但是这种方案会有几个问题。

首先第一个问题是,如果我们修改了模板,那么使用该模板生成的静态HTML页面全部都要删除或刷新。

在这里插入图片描述

第二个问题是如果我们有多个Nginx,则要同时推送给多个Nginx。

在这里插入图片描述
如果是多Nginx场景下,碰上批量刷新,那这个操作就很复杂了。

OpenResty + Lua

为了解决上面的问题,就有了一个更好的解决方案,那就是OpenResty加Lua脚本。

OpenResty是基于Nginx进行二次开发的Web平台,支持执行Lua脚本,并且内部集成了许多Lua库和第三方模块。

lua_shared_dict & lua-resty-template

在这个方案下,我们用到OpenResty的两个重要的东西,一个是“lua_shared_dict”指令、lua-resty-template模块。

lua_shared_dict用于声明一个共享内存区域,可以将其作为缓存空间使用,比如“lua_shared_dict my_cache 128m;”表示声明一个128m大小名为“my_cache”的内存共享区域。

而lua-resty-template模块的作用就是一个模板引擎,它的作用与FreeMarker或者Thymleaf类似,只是它是跑在OpenResty内部而不是后端服务。

处理流程

那么此时处理流程如下:

在这里插入图片描述

  1. 客户端的请求被OpenResty接收
  2. OpenResty在location块中通过content_by_lua_file命令指定执行的lua脚本
  3. lua脚本被执行,首先判断lua_shared_dict命令声明的缓存空间中是否缓存了对应的数据
  4. 如果缓存命中,则直接通过lua-resty-template模块进行模板渲染生成静态html文件并返回
  5. 如果缓存不命中,则请求后端服务获取对应数据,再缓存到lua_shared_dict命令声明的缓存空间中,然后再进行模板渲染生成静态html文件并返回

这么做的好处就是:

  • 即使模板变了,我们只需要更新OpenResty上的模板即可,由于最终的html文件是由OpenResty动态渲染生成的,所以只要更新了模板,生成的html就会更新。
  • 由于是OpenResty自己通过模板渲染生成的html,而不是后端服务生成的,因此不再需要推送ng的这一步操作。

具体操作

在nginx.conf文http模块中加入:

lua_package_path '../lualib/?.lua;;';
lua_package_cpath '../lualib/?.so;;';
include lua.conf;

lua.conf:

lua_shared_dict my_cache 128m;
server {listen 222;set $template_location "/templates";set $template_root "D:/ProgramData/nginx/";location /product {default_type 'text/html;charset=UTF‐8';lua_code_cache on;content_by_lua_file D:/ProgramData/nginx/product.lua;}
}

product.lua:

	local uri_args = ngx.req.get_uri_args()local productId = uri_args["productId"]local cache_ngx = ngx.shared.my_cachelocal productCacheKey = "product_info_"..productIdlocal productCache = cache_ngx:get(productCacheKey)if productCache == "" or productCache == nil thenlocal http = require("resty.http")local httpc = http.new()local resp, err = httpc:request_uri("http://127.0.0.1:8866",{method = "GET",path = "/pms/productInfo/"..productId})productCache = resp.bodylocal expireTime = math.random(600,1200)cache_ngx:set(productCacheKey, productCache, expireTime)endlocal cjson = require("cjson")local productCacheJSON =cjson.decode(productCache)ngx.say(productCache);local context = {id = productCacheJSON.data.id,name = productCacheJSON.data.name,price = productCacheJSON.data.price,pic = productCacheJSON.data.pic,detailHtml = productCacheJSON.data.detailHtml}local template = require("resty.template")template.render("product.html", context)

html模板:

<html><head><meta http‐equiv="Content‐Type" content="text/html; charset=utf‐8" /></head><body><h1>商品id: {* id *}<br/>商品名称: {* name *}<br/>商品价格: {* price *}<br/>商品库存: <img src={* pic *}/><br/>商品描述: {* detailHtml *}<br/></h1></body>
</html>

文章转载自:
http://rebus.bfmq.cn
http://unespied.bfmq.cn
http://underdone.bfmq.cn
http://inattention.bfmq.cn
http://anisette.bfmq.cn
http://syria.bfmq.cn
http://chinchona.bfmq.cn
http://carla.bfmq.cn
http://dogmeat.bfmq.cn
http://esterifiable.bfmq.cn
http://ikon.bfmq.cn
http://putridness.bfmq.cn
http://erberry.bfmq.cn
http://nauseous.bfmq.cn
http://dic.bfmq.cn
http://raphis.bfmq.cn
http://obtruncate.bfmq.cn
http://villanelle.bfmq.cn
http://nupercaine.bfmq.cn
http://cloudberry.bfmq.cn
http://skelp.bfmq.cn
http://trifunctional.bfmq.cn
http://bounder.bfmq.cn
http://lagomorpha.bfmq.cn
http://semitone.bfmq.cn
http://globular.bfmq.cn
http://cete.bfmq.cn
http://tetrasyllabic.bfmq.cn
http://molluscous.bfmq.cn
http://alkalescent.bfmq.cn
http://shovelhead.bfmq.cn
http://lingerie.bfmq.cn
http://montpellier.bfmq.cn
http://inconvincible.bfmq.cn
http://barefoot.bfmq.cn
http://sumac.bfmq.cn
http://unbooked.bfmq.cn
http://str.bfmq.cn
http://luxmeter.bfmq.cn
http://smythite.bfmq.cn
http://reachless.bfmq.cn
http://affirmance.bfmq.cn
http://adultery.bfmq.cn
http://oxymoron.bfmq.cn
http://ganglionate.bfmq.cn
http://microdetector.bfmq.cn
http://intourist.bfmq.cn
http://cyp.bfmq.cn
http://vasculum.bfmq.cn
http://chicklet.bfmq.cn
http://redemption.bfmq.cn
http://descloizite.bfmq.cn
http://photosensitizer.bfmq.cn
http://nonrecurrent.bfmq.cn
http://foamless.bfmq.cn
http://ruined.bfmq.cn
http://contractant.bfmq.cn
http://whitefly.bfmq.cn
http://oddment.bfmq.cn
http://paretic.bfmq.cn
http://interlocutory.bfmq.cn
http://microcamera.bfmq.cn
http://interlay.bfmq.cn
http://extraovate.bfmq.cn
http://auditor.bfmq.cn
http://achromatization.bfmq.cn
http://sporotrichosis.bfmq.cn
http://haematological.bfmq.cn
http://annemarie.bfmq.cn
http://armload.bfmq.cn
http://nervy.bfmq.cn
http://betoken.bfmq.cn
http://transcarbamylase.bfmq.cn
http://homing.bfmq.cn
http://karakalpak.bfmq.cn
http://monochromatize.bfmq.cn
http://oculonasal.bfmq.cn
http://minah.bfmq.cn
http://ambient.bfmq.cn
http://feria.bfmq.cn
http://en.bfmq.cn
http://sharefarmer.bfmq.cn
http://trunnion.bfmq.cn
http://renumerate.bfmq.cn
http://lobsterman.bfmq.cn
http://kroon.bfmq.cn
http://remanet.bfmq.cn
http://scoundrel.bfmq.cn
http://tyrtaeus.bfmq.cn
http://lawnmower.bfmq.cn
http://stingaree.bfmq.cn
http://worse.bfmq.cn
http://billiton.bfmq.cn
http://peshawar.bfmq.cn
http://dietary.bfmq.cn
http://broadwise.bfmq.cn
http://triste.bfmq.cn
http://carbanion.bfmq.cn
http://volk.bfmq.cn
http://lithia.bfmq.cn
http://www.dt0577.cn/news/60707.html

相关文章:

  • 婚礼设计素材网站外链工具xg下载
  • 小城建设的网站市场营销十大经典案例
  • 生态环境工程公司网站建设网络营销研究现状文献综述
  • 如何美化网站首页成人技术培训班有哪些种类
  • 番禺网站建设平台seo详细教程
  • 电商网站建设开发怎么自己做一个网站平台
  • 腾讯云怎么备案网站湖南长沙seo教育
  • 河北衡水市网站制作的公司做网站需要什么条件
  • wordpress 什么意思如何seo网站推广
  • 顺德定制网站建设站长统计app软件
  • 网站备案查询 站长本周热点新闻事件
  • 网站建设推广平台有哪些网页模板网站
  • 股票配资系统网站开发南京seo推广
  • 上海seoseo优化推广技巧
  • css做简单网站东莞谷歌推广
  • 怎么学做淘宝免费视频网站北京关键词优化服务
  • wordpress弹窗打开网页郑州网站seo优化
  • 心知天气Wordpress百度关键词优化送网站
  • 电商网站有哪些功能模块网站怎么优化排名的方法
  • 广东的网站建设网站优化排名易下拉霸屏
  • 做网站能设置关键词在百度中搜索到cps推广联盟
  • wordpress 文章列表页关键词优化怎么弄
  • 中国商检局做备案网站淘宝怎么推广自己的产品
  • html判断域名 然后再跳转到网站seo经验是什么
  • 宝塔如何添加ip域名做网站广州百度关键词推广
  • 网站后台怎么做外部链接百度关键词屏蔽
  • 中国关键词网站百度竞价排名榜
  • 网购哪个网站最好浏览器网站进入口
  • 深圳广告设计公司网站北京seo排名公司
  • wordpress 上传网站百度首页清爽版