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

ARC: The eviction event-handler is not called when manually removing an entry #22

Closed
erwanor opened this issue Apr 13, 2018 · 0 comments
Labels
ARC ARC module bug Something isn't working good first issue Good for newcomers v2

Comments

@erwanor
Copy link
Owner

erwanor commented Apr 13, 2018

Good: (simple.go)

func (c *SimpleCache) remove(key interface{}) bool {
	item, ok := c.store[key]
	if ok {
		delete(c.store, key)
		if c.evictedFunc != nil {
			c.evictedFunc(key, item.value)
		}
		return true
	}
	return false
}

This is the internal remove function. Let us walk through it:

  1. We check if an entry is in the cache
  2. If it is we remove it (delete(c.store, key))
  3. We check if we have a defined eviction handler
  4. If we do we call it
  5. Otherwise we return

Bad:

func (c *ARC) Remove(key interface{}) bool {
	c.mu.Lock()
	defer c.mu.Unlock()

	elt, exists := c.store[key]
	if !exists {
		return false
	}

	if elt.parent != nil {
		elt.parent.Remove(elt.element)
	}

	delete(c.store, elt.key)
	c.size--
	return true
}

Goal: Make the good behavior consistent across the library

@erwanor erwanor added bug Something isn't working good first issue Good for newcomers v2 labels Apr 13, 2018
@erwanor erwanor closed this as completed Apr 14, 2018
@erwanor erwanor added the ARC ARC module label Apr 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARC ARC module bug Something isn't working good first issue Good for newcomers v2
Projects
None yet
Development

No branches or pull requests

1 participant