zoukankan      html  css  js  c++  java
  • nginx-cache

    test.conf

    proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;
    
    server {
      listen      80;
      server_name testyhl.com;
    
      location / {
        proxy_cache my_cache;
        proxy_pass http://127.0.0.1:8888;
        proxy_set_header Host $host;
      }
    }

     server.js

    const http = require('http')
    const fs = require('fs')
    
    const wait = (seconds) => {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve()
        }, seconds * 1000)
      })
    }
    
    http.createServer((request, response) => {
      console.log('requres come', request.url)
    
      if (request.url === '/') {
        const html = fs.readFileSync('test.html', 'utf-8')
    
        response.writeHead(200, {
          'Content-Type': 'text/html'
        })
    
        response.end(html)
      }
    
      if (request.url === '/data') {
        response.writeHead(200, {
          'Cache-Control': 'max-age=5, s-maxage=20, private',
        'Vary': 'X-Test-Cache'
    }) wait(2).then(() => response.end('success')) } }).listen(8888) console.log('server listening on 8888')

     

     test.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <div>This is content, and data is: <span id="data"></span></div>
    </body>
    <script>
      fetch('/data').then((res) => {
        return res.text()
      }).then((text) => {
        document.getElementById('data').innerText = text
      })
    </script>
    </html>
  • 相关阅读:
    关于文件路径的生成
    re模块小结
    logging模块知识点及应用小结
    微信小程序上传图片
    小程序图表插件
    小程序实现多图上传、预览
    微信小程序实现验证码倒计时效果
    微信小程序上传图片,视频及预览
    小程序实现星级打分
    小程序获取系统日期时间
  • 原文地址:https://www.cnblogs.com/ladybug7/p/12357705.html
Copyright © 2011-2022 走看看