我可以使用缓存装饰器保存任何功能调用结果吗?

发布于 2025-01-31 11:24:20 字数 237 浏览 3 评论 0原文

我知道@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文