我可以使用缓存装饰器保存任何功能调用结果吗?
我知道@cache
装饰器被用作实施记忆的快速方法,
可以在其他上下文上使用它,例如用于确定性功能(返回相同的结果提供了相同的参数)? 如果功能是非确定性的,我应该避免它吗?
这就是文档所说的
返回与lru_cache(maxsize = none)相同,在函数参数上创建一个薄的包装器
我想知道当函数没有参数时会发生什么
I'm aware that @cache
decorator is used as quick way to implement memoization
Is is possible to use it on other contexts, like for deterministic functions (that return the same result provided the same arguments)?
Should I avoid it if the function is non-deterministic?
This is what the doc says
Returns the same as lru_cache(maxsize=None), creating a thin wrapper around a dictionary lookup for the function arguments
I wonder what happens when the function takes no arguments
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论