Skip to content

Commit 2c5f6dc

Browse files
committed
if generated, ETags now use a random value to keep clean cache states
1 parent f6fc869 commit 2c5f6dc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ When using the Cache-Control header, you can omit the custom `x-cache-timeout` h
8484
#### Direct usage:
8585
```js
8686
res.setHeader('cache-control', 'private, no-cache, max-age=300')
87-
res.setHeader('etag', '1')
87+
res.setHeader('etag', 'cvbonrw6g00')
8888

8989
res.end('5 minutes cacheable content here....')
9090
```
@@ -97,7 +97,7 @@ res.setHeader('x-cache-timeout', '5 minutes')
9797
The middleware will now transparently generate default `Cache-Control` and `ETag` headers as described below:
9898
```js
9999
res.setHeader('cache-control', 'private, no-cache, max-age=300')
100-
res.setHeader('etag', '1')
100+
res.setHeader('etag', 'ao8onrw6gbt') // random ETag value
101101
```
102102
This will enable browser clients to keep a copy of the cache on their side, but still being forced to validate
103103
the cache state on the server before using the cached response, therefore supporting gateway based cache invalidation.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const middleware = (opts) => async (req, res, next) => {
8484
}
8585
// setting ETag if absent
8686
if (!payload.headers[CACHE_ETAG]) {
87-
payload.headers[CACHE_ETAG] = '1'
87+
payload.headers[CACHE_ETAG] = Math.random().toString(36).substring(2, 16)
8888
}
8989

9090
// cache response

0 commit comments

Comments
 (0)