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: allow replacement of oldest key #253

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

doc-han
Copy link

@doc-han doc-han commented Jul 6, 2021

Feature

This pull request is to allow the auto replacement of the oldest key when trying to do a set operation and the max amount of keys has been reached.
Requested by #232

Example

const nodeCache = require("node-cache");
const myCache = new nodeCache({maxKeys: 2, replaceOldestKey: true});

myCache.set("one", "This is the first key");
myCache.set("two", "This is the second key");
// from here maxKeys has been reached, hence, the oldest key which is "one" gets removed
myCache.set("three", "This is the third key");
console.log(myCache.keys());
// output: ["two", "three"]

@cekvenich2
Copy link

Is there a fork where this is included?

@doc-han
Copy link
Author

doc-han commented Nov 12, 2021

#212 will make the code on this fix better. Since a Map keeps the order of insertion it'll be easier to locate the oldest key.

@Recodify
Copy link

Recodify commented Jan 21, 2022

Would really love this to be merged! Really useful for allowing you to set some sort of vague limit on the size the cache is allow to grow to without preventing new items being inserted. A MAX_HEAP_SIZE option that utilised this "allow replacement of oldest key" method on new insertions would be the holy grail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants