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

Would you consider a PR for cache resize? #37

Open
kevburnsjr opened this issue Jan 13, 2018 · 1 comment
Open

Would you consider a PR for cache resize? #37

kevburnsjr opened this issue Jan 13, 2018 · 1 comment

Comments

@kevburnsjr
Copy link
Contributor

kevburnsjr commented Jan 13, 2018

I'm using golang-lru in an HTTP microcache.

I'd like to be able to specify my cache's size in bytes rather than length.
I have a pretty good idea of how I want to do it, but it will require resizing the cache length dynamically.
Would you consider a PR adding the following methods?

// Resize changes the cache size
func (c *Cache) Resize(size int) (evicted int) {
	c.lock.Lock()
	evicted = c.lru.Resize(size)
	c.lock.Unlock()
	return evicted
}
// Resize changes the cache size
func (c *LRU) Resize(size int) (evicted int) {
	diff := c.Len() - size
	if diff < 0 {
		diff = 0
	}
	for i:= 0; i < diff; i++ {
		c.removeOldest()
	}
	c.size = size
	return diff
}
@armon
Copy link
Member

armon commented Feb 1, 2018

@kevburnsjr Sure, this seems like a valuable feature

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

No branches or pull requests

2 participants