数据库打开/关闭频率 [英] Database Open/Close Frequency

查看:70
本文介绍了数据库打开/关闭频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个聊天应用程序,在聊天中,我们从服务器获取了大量更新.而且我们还将更新保存到本地SQLite数据库文件中.

在每次插入/更新后,有人可以建议我关闭数据库还是在实际需要时关闭数据库?

解决方案

关闭连接将丢弃页面缓存,并要求检查架构版本并在下次打开时重新解析整个架构./p>

在大多数应用中,没有足够的数据库访问权限,因此,连续重新打开数据库的开销实际上会变得明显.但这没有理由在您的应用程序中添加无用的代码.

请注意,SQLiteDatabase对象是引用计数.因此,如果您使用的是全局开放帮助程序实例,则可以通过额外的getWritableDatabase()调用使数据库保持打开状态,即使您所有其他代码都调用close().

I am working on a chat application and in chat we are getting lots of update from server. And we are also saving the updates into the local SQLite database file.

Can someone suggest me, after every single insertion/update, should we close the database or we should close the database when it is actually needed ?

解决方案

Closing the connection throws away the page cache, and requires that the schema version is checked and the entire schema is re-parsed the next time it is opened.

In most apps, there are not enough database accesses so that the overhead of continually re-opening the database would actually become noticeable. But this is no reason to add useless code to your app.

Please note that the SQLiteDatabase object is reference counted. So if you are using a global open helper instance, you can keep the DB open with an extra getWritableDatabase() call, even when all your other code calls close().

这篇关于数据库打开/关闭频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆