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

Remove redundant key from arcItem to save memory #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 6 additions & 8 deletions arc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *ARC) replace(key interface{}) {
if ok {
delete(c.items, old)
if c.evictedFunc != nil {
c.evictedFunc(item.key, item.value)
c.evictedFunc(old, item.value)
}
}
}
Expand Down Expand Up @@ -94,7 +94,6 @@ func (c *ARC) set(key, value interface{}) (interface{}, error) {
} else {
item = &arcItem{
clock: c.clock,
key: key,
value: value,
}
c.items[key] = item
Expand Down Expand Up @@ -141,7 +140,7 @@ func (c *ARC) set(key, value interface{}) (interface{}, error) {
if ok {
delete(c.items, pop)
if c.evictedFunc != nil {
c.evictedFunc(item.key, item.value)
c.evictedFunc(pop, item.value)
}
}
}
Expand Down Expand Up @@ -209,7 +208,7 @@ func (c *ARC) getValue(key interface{}, onLoad bool) (interface{}, error) {
delete(c.items, key)
c.b1.PushFront(key)
if c.evictedFunc != nil {
c.evictedFunc(item.key, item.value)
c.evictedFunc(key, item.value)
}
}
}
Expand All @@ -226,7 +225,7 @@ func (c *ARC) getValue(key interface{}, onLoad bool) (interface{}, error) {
c.t2.Remove(key, elt)
c.b2.PushFront(key)
if c.evictedFunc != nil {
c.evictedFunc(item.key, item.value)
c.evictedFunc(key, item.value)
}
}
}
Expand Down Expand Up @@ -364,8 +363,8 @@ func (c *ARC) Purge() {
defer c.mu.Unlock()

if c.purgeVisitorFunc != nil {
for _, item := range c.items {
c.purgeVisitorFunc(item.key, item.value)
for key, item := range c.items {
c.purgeVisitorFunc(key, item.value)
}
}

Expand Down Expand Up @@ -401,7 +400,6 @@ type arcList struct {

type arcItem struct {
clock Clock
key interface{}
value interface{}
expiration *time.Time
}
Expand Down