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

Is cache implementation thread-safe? #124

Closed
amorey opened this issue Aug 30, 2022 · 2 comments
Closed

Is cache implementation thread-safe? #124

amorey opened this issue Aug 30, 2022 · 2 comments

Comments

@amorey
Copy link

amorey commented Aug 30, 2022

I noticed that shaj13/libcache's documentation says that lru.New() initializes a non-thread safe cache (https://github.com/shaj13/libcache/blob/master/lru/lru.go#L15) and I couldn't find any code to handle thread safety in go-guardian so I'm wondering, is go-guardian thread-safe? Can it be used in the request path of a go web server safely?

@shaj13
Copy link
Owner

shaj13 commented Aug 30, 2022

@amorey thank you for reaching out, shaj13/libcache's and go-guardian, are operate completely independently.

go-guradian does not implement the underlying cache it only exposes an interface so the user can write their own implementation or use libcache.

However, go-guradian and libcache threaded safe and it's already running in production.

Regarding your question, all subpackage (lru, mru, etc..) initializes a non-thread safe, but the parent pkg offers a safe thread cache see example so the user can choose a safe cache or unsafe cache.

@amorey
Copy link
Author

amorey commented Aug 30, 2022

@shaj13 Thanks for your quick reply! I see, I was confused by the New() method in the lru package which returns a nonsafe cache but I see now that libcache.LRU.New() actually returns a thread-safe wrapper from the libcache package. Thanks again for help.

@amorey amorey closed this as completed Aug 30, 2022
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