模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    etag缓存模块 - Web开发参考——模具行业从业者必备知识手册

    社区公告
    1
    1
    0
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>etag</h2>

      <p>[![NPM Version][npm-image]][npm-url]</p>
      <p>[![NPM Downloads][downloads-image]][downloads-url]</p>
      <p>[![Node.js Version][node-version-image]][node-version-url]</p>
      <p>[![Build Status][travis-image]][travis-url]</p>
      <p>[![Test Coverage][coveralls-image]][coveralls-url]</p>

      <p>Create simple HTTP ETags</p>

      <p>This module generates HTTP ETags (as defined in RFC 7232) for use in</p>
      <p>HTTP responses.</p>

      <h3>Installation</h3>

      <p>This is a <a href="https://nodejs.org/en/">Node.js</a> module available through the</p>
      <p><a href="https://www.npmjs.com/">npm registry</a>. Installation is done using the</p>
      <p><a href="https://docs.npmjs.com/getting-started/installing-npm-packages-locally"><code>npm install</code> command</a>:</p>

      <pre><code>
      $ npm install etag
      </code></pre>

      <h3>API</h3>

      <p><!-- eslint-disable no-unused-vars --></p>

      <pre><code>
      var etag = require('etag')
      </code></pre>

      <h4>etag(entity, [options])</h4>

      <p>Generate a strong ETag for the given entity. This should be the complete</p>
      <p>body of the entity. Strings, <code>Buffer</code>s, and <code>fs.Stats</code> are accepted. By</p>
      <p>default, a strong ETag is generated except for <code>fs.Stats</code>, which will</p>
      <p>generate a weak ETag (this can be overwritten by <code>options.weak</code>).</p>

      <p><!-- eslint-disable no-undef --></p>

      <pre><code>
      res.setHeader('ETag', etag(body))
      </code></pre>

      <p>#### Options</p>

      <p><code>etag</code> accepts these properties in the options object.</p>

      <p>##### weak</p>

      <p>Specifies if the generated ETag will include the weak validator mark (that</p>
      <p>is, the leading <code>W/</code>). The actual entity tag is the same. The default value</p>
      <p>is <code>false</code>, unless the <code>entity</code> is <code>fs.Stats</code>, in which case it is <code>true</code>.</p>

      <h3>Testing</h3>

      <pre><code>
      $ npm test
      </code></pre>

      <h3>Benchmark</h3>

      <pre><code>
      $ npm run-script bench

      etag@1.8.1 bench nodejs-etag
      node benchmark/index.js

      http_parser@2.7.0
      node@6.11.1
      v8@5.1.281.103
      uv@1.11.0
      zlib@1.2.11
      ares@1.10.1-DEV
      icu@58.2
      modules@48
      openssl@1.0.2k

      node benchmark/body0-100b.js

      100B body

      4 tests completed.

      buffer - strong x 258,647 ops/sec ±1.07% (180 runs sampled)
      buffer - weak x 263,812 ops/sec ±0.61% (184 runs sampled)
      string - strong x 259,955 ops/sec ±1.19% (185 runs sampled)
      string - weak x 264,356 ops/sec ±1.09% (184 runs sampled)

      node benchmark/body1-1kb.js

      1KB body

      4 tests completed.

      buffer - strong x 189,018 ops/sec ±1.12% (182 runs sampled)
      buffer - weak x 190,586 ops/sec ±0.81% (186 runs sampled)
      string - strong x 144,272 ops/sec ±0.96% (188 runs sampled)
      string - weak x 145,380 ops/sec ±1.43% (187 runs sampled)

      node benchmark/body2-5kb.js

      5KB body

      4 tests completed.

      buffer - strong x 92,435 ops/sec ±0.42% (188 runs sampled)
      buffer - weak x 92,373 ops/sec ±0.58% (189 runs sampled)
      string - strong x 48,850 ops/sec ±0.56% (186 runs sampled)
      string - weak x 49,380 ops/sec ±0.56% (190 runs sampled)

      node benchmark/body3-10kb.js

      10KB body

      4 tests completed.

      buffer - strong x 55,989 ops/sec ±0.93% (188 runs sampled)
      buffer - weak x 56,148 ops/sec ±0.55% (190 runs sampled)
      string - strong x 27,345 ops/sec ±0.43% (188 runs sampled)
      string - weak x 27,496 ops/sec ±0.45% (190 runs sampled)

      node benchmark/body4-100kb.js

      100KB body

      4 tests completed.

      buffer - strong x 7,083 ops/sec ±0.22% (190 runs sampled)
      buffer - weak x 7,115 ops/sec ±0.26% (191 runs sampled)
      string - strong x 3,068 ops/sec ±0.34% (190 runs sampled)
      string - weak x 3,096 ops/sec ±0.35% (190 runs sampled)

      node benchmark/stats.js

      stat

      4 tests completed.

      real - strong x 871,642 ops/sec ±0.34% (189 runs sampled)
      real - weak x 867,613 ops/sec ±0.39% (190 runs sampled)
      fake - strong x 401,051 ops/sec ±0.40% (189 run


      有没有同行遇到过同样的问题?分享一下经验。
      </code></pre>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors