Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ This major version has been reworked to avoid breaking changes but some edge-cas

## New Features

????
### Cache status header

You can now opt-in to get a cache status header in the response
Use `res.express_redis_cache_status=true|false` - default to false
The response will include the header `redis-cache-status=Hit|Miss`

# Changes between 0.0.8 and 0.1.x

Expand All @@ -29,6 +33,7 @@ We introduced the `(Boolean) res.express_redis_cache_skip` property which, if se

The code now emits a *deprecated* event when stumbling upon a deprecated part of the code. View below for more info.


## Fixes

No fixes have been made.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ cache.on('deprecated', function (deprecated) {
});
```

## Cache status header

You can opt-in to get a header in the response that gives you the status of the redis cache.
Use `res.express_redis_cache_status=true|false` - default to false

The response will include the header `redis-cache-status=Hit|Miss`

# The Entry Model

This is the object synopsis we use to represent a cache entry:
Expand Down
6 changes: 6 additions & 0 deletions lib/ExpressRedisCache/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ function route() {
/** if it's cached, display cache **/

if (cache.length && cache[0].body != null) {
if (res.express_redis_cache_status) {
res._headers["redis-cache-status"] = "Hit";
}
res.contentType(cache[0].type || "text/html");
if (binary) {
//Convert back to binary buffer
Expand All @@ -177,6 +180,9 @@ function route() {
res.send(cache[0].body);
}
} else {
if (res.express_redis_cache_status) {
res._headers["redis-cache-status"] = "Miss";
}
/** otherwise, cache request **/
/** wrap res.send **/
let send = res.send.bind(res);
Expand Down
1 change: 1 addition & 0 deletions test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe("route", () => {
throw error;
}
res._headers["cache-control"].should.equal("max-age=60000");
res._headers["redis-cache-status"].should.equal(undefined);
res.send("hello folks!");
done();
});
Expand Down