Skip to content

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.

4 participants