Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added limit key counts for memory cache #222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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