-
Notifications
You must be signed in to change notification settings - Fork 273
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
Extend SimpleCache to allow for unbounded growth #38
Conversation
simple.go
Outdated
@@ -18,7 +18,11 @@ func newSimpleCache(cb *CacheBuilder) *SimpleCache { | |||
} | |||
|
|||
func (c *SimpleCache) init() { | |||
c.items = make(map[interface{}]*simpleItem, c.size) | |||
if c.size == -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want size==0
to means unbounded, so could you change to c.size <= 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
simple.go
Outdated
@@ -58,7 +62,7 @@ func (c *SimpleCache) set(key, value interface{}) (interface{}, error) { | |||
item.value = value | |||
} else { | |||
// Verify size not exceeded | |||
if len(c.items) >= c.size { | |||
if (len(c.items) >= c.size) && c.size != -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronwinter
ref: https://github.com/bluele/gcache/pull/38/files#r127405430
Could you change to if c.size > 0 && len(c.items) >= c.size
?
simple.go
Outdated
@@ -18,7 +18,11 @@ func newSimpleCache(cb *CacheBuilder) *SimpleCache { | |||
} | |||
|
|||
func (c *SimpleCache) init() { | |||
c.items = make(map[interface{}]*simpleItem, c.size) | |||
if c.size == -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
When do you guys expect this to be merged?
This is exactly the change I've been waiting for...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kogan69 Hi, my bad, I sort of forgot about it. I will complete the PR by Wednesday this week.
Thank you so much!
Cheers,
LK
… On Oct 1, 2017, at 7:38 PM, Erwan ***@***.***> wrote:
@aaronwinter commented on this pull request.
In simple.go:
> @@ -18,7 +18,11 @@ func newSimpleCache(cb *CacheBuilder) *SimpleCache {
}
func (c *SimpleCache) init() {
- c.items = make(map[interface{}]*simpleItem, c.size)
+ if c.size == -1 {
@kogan69 Hi, my bad sort of forgot about it. I will complete the PR by Wednesday this week.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@kogan69 I fixed the PR. Let me add a test suite for it and then it should be good to go for review and merge. |
Added the test case, I'd like to add another to test for This one is ready for review @bluele |
Thanks, @aaronwinter ! |
In this PR, we allow users to create a (SimpleCache) cache with no artificial upper bound on the number of elements that it can host. To achieve that, the user will specify a
size <= 0
before building the cache.