Skip to content

Commit b1f3ca3

Browse files
committed
Use x-apicache-revalidate request header to force cache to revalidate
1 parent 3ae6fe7 commit b1f3ca3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/apicache.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,11 @@ function ApiCache() {
639639
// attempt cache hit
640640
var redis = opt.redisClient
641641
var cached = !redis ? memCache.getValue(key) : null
642+
// skip cache load when x-apicache-revalidate is present
643+
var revalidate = req.headers['x-apicache-revalidate']
642644

643645
// send if cache hit from memory-cache
644-
if (cached) {
646+
if (!revalidate && cached) {
645647
var elapsed = new Date() - req.apicacheTimer
646648
debug('sending cached (memory-cache) version of', key, logDuration(elapsed))
647649

@@ -650,7 +652,7 @@ function ApiCache() {
650652
}
651653

652654
// send if cache hit from redis
653-
if (redis && redis.connected) {
655+
if (!revalidate && redis && redis.connected) {
654656
try {
655657
redis.hgetall(key, function(err, obj) {
656658
if (!err && obj && obj.response) {

0 commit comments

Comments
 (0)