Skip to content

add Cache constructor#55

Closed
zhangfan2012fall wants to merge 4 commits into
ptarjan:masterfrom
zhangfan2012fall:master
Closed

add Cache constructor#55
zhangfan2012fall wants to merge 4 commits into
ptarjan:masterfrom
zhangfan2012fall:master

Conversation

@zhangfan2012fall
Copy link
Copy Markdown
Contributor

#43 Not sure what happened to that PR, I also need to be able to create new cache instance.

Instead of a factory method, I added a constructor

Comment thread index.js Outdated
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a constructor param instead of just using the setter after you made it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptarjan I thought it would be easier to use the debug feature.
Instead of call the setter explicitly, you can just add true, when you create the instance.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, that would be easier for any option. I'd prefer to not single out this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, isn't debug the only option ? 😃

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but this library will be around for many years, and will probably get options along the way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, I removed it.

@weastmann
Copy link
Copy Markdown

@zhangfan2012fall
I think the result is not entirely as intended. Creating multiple instances of Cache will refer to the same key mapping.

var Cache = require("memory-cache").Cache;

var c1 = new Cache();
c1.put("test", "thing");
var c2 = new Cache();
c2.get("test") // returns "thing" 

The tests pass because only one instance of the Cache is ever created/referred to.

@zhangfan2012fall
Copy link
Copy Markdown
Contributor Author

@weastmann fixed, I dropped the ball here 😭

@weastmann
Copy link
Copy Markdown

@zhangfan2012fall Looks good.

@frontierpsycho
Copy link
Copy Markdown

I came to propose exactly this feature.

@michaeljones
Copy link
Copy Markdown

👍 I'd like to see this integrated as well.

@debrouxl
Copy link
Copy Markdown

debrouxl commented Apr 7, 2016

I would like to see this kind of functionality integrated as well :)
I liked the hits() and misses() APIs, but the fact that memory-cache is currently a singleton eliminated it from the options for an internal project.

@ptarjan
Copy link
Copy Markdown
Owner

ptarjan commented Apr 7, 2016

@debrouxl if you want to rebase it, I'm willing to take it.

@simon300000
Copy link
Copy Markdown

simon300000 commented Apr 23, 2016

const cache = require('memory-cache');
delete require.cache[require.resolve('memory-cache')]
const cache2 = require('memory-cache');

cache.put('foo', '233');
cache2.put('foo', '666');

console.log(cache.get('foo'))//233
console.log(cache2.get('foo'))//666

→_→

This was referenced Apr 23, 2016
@ptarjan ptarjan closed this Jun 22, 2016
ptarjan added a commit that referenced this pull request Jun 19, 2017
add Cache constructor (rebase of #55)
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.

7 participants