仅读取数据后是否需要关闭ZODB连接

发布于 2024-10-07 00:17:53 字数 217 浏览 0 评论 0原文

我正在使用 ZODB 进行 python 对象持久化。我使用 web2py 作为框架。

我使用的 ZODB 数据库仅用于读取。我已经编写了用于在模型中打开数据库的代码。然后,connection.root() 对象被缓存在 RAM 中,以便它保留在那里以应对其他请求。

我的问题是,如果 ZODB 数据库仅用于读取访问并且没有挂起的写入,是否有必要关闭该数据库?

I am using ZODB for my python object persistence. I am using web2py as a framework.

The ZODB database I am using is accessed only for reads. I have written the code for opening the database inside my models. The connection.root() object is then cached in RAM so it stays there for other requests.

My question is, is it necessary to close a ZODB database if it is used only for read access and there are no pending writes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落星ぅ辰 2024-10-14 00:17:53

不,你不需要关闭它。每个打开的连接确实会消耗一点内存等,但听起来无论如何你都不会拥有数千个连接,每个 web2py 进程只需要一个

No you don't need to close it. Each open connection does consume a little memory etc, but it sounds like you aren't going to have thousands of them anyway, just one per web2py process

栩栩如生 2024-10-14 00:17:53

您不必关闭它,但如果您想避免缓存的对象耗尽您的内存,您应该定期运行 connection.cacheMinimize()。如果您还定期写入数据并提交,则可以跳过这一点,因为 commit() 包含 cacheMinimize()

You don't have to close it, but you should run connection.cacheMinimize() regularly, if you want to avoid, that the cached objects eats up your memory. If you're also writing data and commit regularly, you can skip that, as commit() includes cacheMinimize().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文