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

on-get callback #36

Closed
uncle-lv opened this issue Nov 6, 2023 · 6 comments
Closed

on-get callback #36

uncle-lv opened this issue Nov 6, 2023 · 6 comments

Comments

@uncle-lv
Copy link
Contributor

uncle-lv commented Nov 6, 2023

I think on_get callback may just be simple like this:

cache = Cache(on_get=on_get)

The callback function.

Callable[[key: Hashable, value: Any],  None]

In fact, I've hardly ever seen a on-get listener in cache libraries. Do we really need it? 🤷

@dgilland
Copy link
Owner

dgilland commented Nov 7, 2023

I'm also not sure on the utility of it, but the callback could also include whether the key there or not. That might make it a little more useful.

@uncle-lv
Copy link
Contributor Author

uncle-lv commented Nov 8, 2023

I'm also not sure on the utility of it, but the callback could also include whether the key there or not. That might make it a little more useful.

If the key is missed, whichever is better is to set the value to None or UNSET?

@dgilland
Copy link
Owner

dgilland commented Nov 8, 2023

If the key is missed, whichever is better is to set the value to None or UNSET?

Another question around this would be whether having value always be the returned value (i.e. the existing value or the default value) and send another variable to indicate whether the key exists would be preferable over having the value only ever be the existing one. Potentially the default value could come from a default function so would having that value potentially be useful? Seems like we'd have more information with the first option.

@uncle-lv
Copy link
Contributor Author

uncle-lv commented Nov 9, 2023

If the key is missed, whichever is better is to set the value to None or UNSET?

Another question around this would be whether having value always be the returned value (i.e. the existing value or the default value) and send another variable to indicate whether the key exists would be preferable over having the value only ever be the existing one. Potentially the default value could come from a default function so would having that value potentially be useful? Seems like we'd have more information with the first option.

Callable[[key: Hashable, value: Any, existed: bool],  None]

Add existed to indicate whether the key has existed. If existed is true, value is the real value. Otherwise, value is the default value.

@dgilland
Copy link
Owner

dgilland commented Nov 9, 2023

Callable[[key: Hashable, value: Any, existed: bool], None]
Add existed to indicate whether the key has existed. If existed is true, value is the real value. Otherwise, value is the default value.

👍

@dgilland
Copy link
Owner

Done in #38

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