It would be really cool if there was a helper function on the cache object which would take a cache key and a callable. Returning either the current value if it exists, or call the given function to set the value and return it. Django has the same feature implemented: https://docs.djangoproject.com/en/5.0/topics/cache/#django.core.cache.cache.get_or_set
I think it should also be possible to type the return value of the function as the return value of the given function:
It would be really cool if there was a helper function on the
cache
object which would take a cache key and a callable. Returning either the current value if it exists, or call the given function to set the value and return it. Django has the same feature implemented: https://docs.djangoproject.com/en/5.0/topics/cache/#django.core.cache.cache.get_or_setI think it should also be possible to type the return value of the function as the return value of the given function: