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

Should perform the function onEvicted when reset the key. #141

Open
whalecold opened this issue Aug 25, 2021 · 0 comments
Open

Should perform the function onEvicted when reset the key. #141

whalecold opened this issue Aug 25, 2021 · 0 comments

Comments

@whalecold
Copy link

The method Get will return false when the key has been expired, the user will reset the key usually. But the method Set

func (c *cache) Set(k string, x interface{}, d time.Duration) {

func (c *cache) Set(k string, x interface{}, d time.Duration) {
	// "Inlining" of set
	var e int64
	if d == DefaultExpiration {
		d = c.defaultExpiration
	}
	if d > 0 {
		e = time.Now().Add(d).UnixNano()
	}
	c.mu.Lock()
	c.items[k] = Item{
		Object:     x,
		Expiration: e,
	}
	// TODO: Calls to mu.Unlock are currently not deferred because defer
	// adds ~200 ns (as of go1.)
	c.mu.Unlock()
}

don't check if has the expired value and perform the onEvicted function, that may lead to unexpected result.

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

1 participant