Is it necessary to close ZODB connections after only reading data
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 qu开发者_开发知识库estion is, is it necessary to close a ZODB database if it is used only for read access and there are no pending writes?
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
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()
.
精彩评论