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

why struct Cache contains pointer to cache? #142

Open
chengxwcq opened this issue Oct 12, 2021 · 2 comments
Open

why struct Cache contains pointer to cache? #142

chengxwcq opened this issue Oct 12, 2021 · 2 comments

Comments

@chengxwcq
Copy link

it looks like struct cache is unnecessary in the code. I notice the comment // If this is confusing, see the comment at the bottom of New(), but i didn't find any explaination

@thediveo
Copy link

go-cache/cache.go

Line 1115 in 46f4078

// This trick ensures that the janitor goroutine (which--granted it

@john-nash-rs
Copy link

IMO, Since, the janitor is working in a go routine on cache , c object. It will never be available for garbage collection. Hence, Cache struct is designed to have cache as a field. If Cache struct is garbage collected, stopJanitor is called using the runtime.setFinalizer. runtime.setFinalizer is used to call a function, here stopJanitor, when the first operand , here C, is garbage collected.

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

3 participants