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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ let cache5min = cache('5 minute') // continue to use normally
// 'cache-control': 'no-cache' // example of header overwrite
},
respectCacheControl: false|true // If true, 'Cache-Control: no-cache' in the request header will bypass the cache.
maxKey: number // When using local memory, it is necessary to limit the max memory of nodejs. If you want to limit the number of keys that can be cached for this. (default is not using)
}
```

Expand Down
4 changes: 3 additions & 1 deletion src/apicache.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function ApiCache() {
},
trackPerformance: false,
respectCacheControl: false,
maxKey: -1,
}

var middlewareOptions = []
Expand Down Expand Up @@ -142,7 +143,8 @@ function ApiCache() {
debug('[apicache] error in redis.hset()')
}
} else {
memCache.add(key, value, duration, expireCallback)
if (globalOptions.maxKey > 0 && memCache.size > globalOptions.maxKey)
memCache.add(key, value, duration, expireCallback)
}

// add automatic cache clearing from duration, includes max limit on setTimeout
Expand Down