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

No safe clear cache function #18

Closed
tugtugtug opened this issue Jun 7, 2021 · 3 comments
Closed

No safe clear cache function #18

tugtugtug opened this issue Jun 7, 2021 · 3 comments

Comments

@tugtugtug
Copy link

This lib fits our use case well, except that there is no safe clear function. Is there any reason we could not have a safe clear cache function?

@anderslanglands
Copy link
Owner

Hi there! The reason there’s no safe clear_cache is because all Ustrs are conceptually a &’static str by design. That is, they are assumed to live forever and this design choice makes it easy to store them in structs etc without worrying about lifetimes, making the use of the library much more ergonomic.

Having a clear_cache() function would invalidate this, and require setting up some kind of lifetime tracking to make sure Ustrs don’t outlive the “phase” of the cache that they were created in, which again would break the ergonomics.

You can of course just unsafe { clear_cache() } yourself if you are SURE that you are not still using any previously created Ustrs, but that responsibility lies with the caller, hence the unsafe.

@tugtugtug
Copy link
Author

got it, thanks @anderslanglands! that makes total sense, and I was just seeking some confirmation if that clear_cache can be ever used if the caller knows that all references are no longer there.

@anderslanglands
Copy link
Owner

You’re welcome! Closing this now.

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