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

Question #150

Open
nassiharel opened this issue Mar 26, 2022 · 1 comment
Open

Question #150

nassiharel opened this issue Mar 26, 2022 · 1 comment

Comments

@nassiharel
Copy link

nassiharel commented Mar 26, 2022

Is there any reason for not using defer when unlocking mutex?

func (c *cache) Get(k string) (interface{}, bool) {
	c.mu.RLock()
        defer c.mu.RUnlock()
	// "Inlining" of get and Expired
	item, found := c.items[k]
	if !found {
		return nil, false
	}
	if item.Expiration > 0 {
		if time.Now().UnixNano() > item.Expiration {
			return nil, false
		}
	}
	return item.Object, true
}
@arp242
Copy link

arp242 commented Mar 26, 2022

It used to have a reasonably significant performance impact. That was improved a few Go versions ago, and now the performance impact is negligible (I benchmarked this for my fork).

Note this package doesn't seem maintained; I have a fork at https://github.com/arp242/zcache with some fixes.

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