<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[etag缓存模块 - Web开发参考——模具行业从业者必备知识手册]]></title><description><![CDATA[<p dir="auto">&lt;h2&gt;etag&lt;/h2&gt;</p>
<p dir="auto">&lt;p&gt;[![NPM Version][npm-image&rsqb;&rsqb;[npm-url]&lt;/p&gt;<br />
&lt;p&gt;[![NPM Downloads][downloads-image&rsqb;&rsqb;[downloads-url]&lt;/p&gt;<br />
&lt;p&gt;[![Node.js Version][node-version-image&rsqb;&rsqb;[node-version-url]&lt;/p&gt;<br />
&lt;p&gt;[![Build Status][travis-image&rsqb;&rsqb;[travis-url]&lt;/p&gt;<br />
&lt;p&gt;[![Test Coverage][coveralls-image&rsqb;&rsqb;[coveralls-url]&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;Create simple HTTP ETags&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;This module generates HTTP ETags (as defined in RFC 7232) for use in&lt;/p&gt;<br />
&lt;p&gt;HTTP responses.&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Installation&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;This is a &lt;a href="<a href="https://nodejs.org/en/" rel="nofollow ugc">https://nodejs.org/en/</a>"&gt;Node.js&lt;/a&gt; module available through the&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="<a href="https://www.npmjs.com/" rel="nofollow ugc">https://www.npmjs.com/</a>"&gt;npm registry&lt;/a&gt;. Installation is done using the&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="<a href="https://docs.npmjs.com/getting-started/installing-npm-packages-locally" rel="nofollow ugc">https://docs.npmjs.com/getting-started/installing-npm-packages-locally</a>"&gt;&lt;code&gt;npm install&lt;/code&gt; command&lt;/a&gt;:&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
$ npm install etag<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;h3&gt;API&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;&lt;!-- eslint-disable no-unused-vars --&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
var etag = require('etag')<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;h4&gt;etag(entity, [options])&lt;/h4&gt;</p>
<p dir="auto">&lt;p&gt;Generate a strong ETag for the given entity. This should be the complete&lt;/p&gt;<br />
&lt;p&gt;body of the entity. Strings, &lt;code&gt;Buffer&lt;/code&gt;s, and &lt;code&gt;fs.Stats&lt;/code&gt; are accepted. By&lt;/p&gt;<br />
&lt;p&gt;default, a strong ETag is generated except for &lt;code&gt;fs.Stats&lt;/code&gt;, which will&lt;/p&gt;<br />
&lt;p&gt;generate a weak ETag (this can be overwritten by &lt;code&gt;options.weak&lt;/code&gt;).&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;!-- eslint-disable no-undef --&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
res.setHeader('ETag', etag(body))<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;#### Options&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;code&gt;etag&lt;/code&gt; accepts these properties in the options object.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;##### weak&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;Specifies if the generated ETag will include the weak validator mark (that&lt;/p&gt;<br />
&lt;p&gt;is, the leading &lt;code&gt;W/&lt;/code&gt;). The actual entity tag is the same. The default value&lt;/p&gt;<br />
&lt;p&gt;is &lt;code&gt;false&lt;/code&gt;, unless the &lt;code&gt;entity&lt;/code&gt; is &lt;code&gt;fs.Stats&lt;/code&gt;, in which case it is &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Testing&lt;/h3&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
$ npm test<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;h3&gt;Benchmark&lt;/h3&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
$ npm run-script bench</p>
<blockquote>
<p dir="auto">etag@1.8.1 bench nodejs-etag<br />
node benchmark/index.js</p>
</blockquote>
<p dir="auto">http_parser@2.7.0<br />
node@6.11.1<br />
v8@5.1.281.103<br />
uv@1.11.0<br />
zlib@1.2.11<br />
ares@1.10.1-DEV<br />
icu@58.2<br />
modules@48<br />
openssl@1.0.2k</p>
<blockquote>
<p dir="auto">node benchmark/body0-100b.js</p>
</blockquote>
<p dir="auto">100B body</p>
<p dir="auto">4 tests completed.</p>
<p dir="auto">buffer - strong x 258,647 ops/sec ±1.07% (180 runs sampled)<br />
buffer - weak   x 263,812 ops/sec ±0.61% (184 runs sampled)<br />
string - strong x 259,955 ops/sec ±1.19% (185 runs sampled)<br />
string - weak   x 264,356 ops/sec ±1.09% (184 runs sampled)</p>
<blockquote>
<p dir="auto">node benchmark/body1-1kb.js</p>
</blockquote>
<p dir="auto">1KB body</p>
<p dir="auto">4 tests completed.</p>
<p dir="auto">buffer - strong x 189,018 ops/sec ±1.12% (182 runs sampled)<br />
buffer - weak   x 190,586 ops/sec ±0.81% (186 runs sampled)<br />
string - strong x 144,272 ops/sec ±0.96% (188 runs sampled)<br />
string - weak   x 145,380 ops/sec ±1.43% (187 runs sampled)</p>
<blockquote>
<p dir="auto">node benchmark/body2-5kb.js</p>
</blockquote>
<p dir="auto">5KB body</p>
<p dir="auto">4 tests completed.</p>
<p dir="auto">buffer - strong x 92,435 ops/sec ±0.42% (188 runs sampled)<br />
buffer - weak   x 92,373 ops/sec ±0.58% (189 runs sampled)<br />
string - strong x 48,850 ops/sec ±0.56% (186 runs sampled)<br />
string - weak   x 49,380 ops/sec ±0.56% (190 runs sampled)</p>
<blockquote>
<p dir="auto">node benchmark/body3-10kb.js</p>
</blockquote>
<p dir="auto">10KB body</p>
<p dir="auto">4 tests completed.</p>
<p dir="auto">buffer - strong x 55,989 ops/sec ±0.93% (188 runs sampled)<br />
buffer - weak   x 56,148 ops/sec ±0.55% (190 runs sampled)<br />
string - strong x 27,345 ops/sec ±0.43% (188 runs sampled)<br />
string - weak   x 27,496 ops/sec ±0.45% (190 runs sampled)</p>
<blockquote>
<p dir="auto">node benchmark/body4-100kb.js</p>
</blockquote>
<p dir="auto">100KB body</p>
<p dir="auto">4 tests completed.</p>
<p dir="auto">buffer - strong x 7,083 ops/sec ±0.22% (190 runs sampled)<br />
buffer - weak   x 7,115 ops/sec ±0.26% (191 runs sampled)<br />
string - strong x 3,068 ops/sec ±0.34% (190 runs sampled)<br />
string - weak   x 3,096 ops/sec ±0.35% (190 runs sampled)</p>
<blockquote>
<p dir="auto">node benchmark/stats.js</p>
</blockquote>
<p dir="auto">stat</p>
<p dir="auto">4 tests completed.</p>
<p dir="auto">real - strong x 871,642 ops/sec ±0.34% (189 runs sampled)<br />
real - weak   x 867,613 ops/sec ±0.39% (190 runs sampled)<br />
fake - strong x 401,051 ops/sec ±0.40% (189 run</p>
<hr />
<p dir="auto">有没有同行遇到过同样的问题？分享一下经验。<br />
&lt;/code&gt;&lt;/pre&gt;</p>
]]></description><link>https://forum.mj7.cn/topic/7209/etag缓存模块-web开发参考-模具行业从业者必备知识手册</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 09:34:44 GMT</lastBuildDate><atom:link href="https://forum.mj7.cn/topic/7209.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Apr 2026 21:54:44 GMT</pubDate><ttl>60</ttl></channel></rss>