想象一下以下情况:
我有一个包含 57,000 个项目的表,我经常在应用程序中使用它来确定目标组等内容。
对于一个几乎不更改其数据的表,是否可以每天查询数据库 300,000 次?如何将其信息存储在我的应用程序中并直接轮询内存中的数据?或者,我是否必须为每一行创建某种自定义数据类型并迭代测试每一行,以检查我想要的结果?
经过一番谷歌搜索后,我能找到的最接近的是内存数据库
谢谢,
- 西奥
Imagine the following:
I have a table of 57,000 items that i regularly use in my application to figure out things like targeting groups etc.
instead of querying the database 300,000 times a day, for a table that hardly ever changes it's data, is there a way to store its information in my application and poll data in memory directly? Or, do I have to create some sort of custom datatype for each row and iterate through testing each row, to check for the results i want?
After some googling, the closest thing i could find is in-memory database
thank you,
- theo
发布评论
评论(4)
SQLite 支持内存表。
SQLite supports in-memory tables.
对于您将查询(并希望立即可用)的 57,000 个项目,我不建议仅实施简单的缓存。对于这么多项目,我要么推荐分布式内存缓存(即使它只有一台机器),例如 Memcache、Velocity 等,要么遵循您使用内存数据库的最初想法。
此外,如果您使用任何成熟的 ORM(例如 NHibernate),您可以实现它以使用分布式缓存工具的客户端,几乎不需要任何工作。许多主要客户都有 NHibernate 实现,包括 Memcache、Velocity 等。这可能是一个更好的解决方案,因为您可以将其仅缓存其真正使用的数据,而不是它可能需要的所有数据。
For 57,000 items that you will be querying against (and want immediately available) I would not recommend implementing just simple caching. For that many items I'd either recommend a distributed memory cache (even if it's only one machine) such as Memcache, Velocity etc or to go with your initial idea of using an in memory database.
Also if you use any full fledged ORM such as NHibernate you can implement it to use clients for the distributed caching tools with almost no work. Many of the major clients have NHibernate implementations for them including Memcache, Velocity and some others. This might be a better solution as you can have it where it's only caching data it truly is using and not all the data it might need.
阅读 缓存
听起来像这样是应用程序级别数据而不是用户级别数据,因此您应该查看“缓存应用程序数据"
以下是缓存数据表的一些示例
Read up on Caching
It sounds like this is application level data rather than user level, so you should look into "Caching Application Data"
Here are some samples of caching datatables
如果您只需要始终使用相同键查找行,那么一个简单的
Dictionary
很可能就满足您的需求。对我来说,57,000 个项目听起来并不算多,除非每行都包含大量数据。但是,如果您需要按不同的列进行搜索,那么内存数据库很可能是最佳选择。If you only need to find rows using the same key all the time, a simple
Dictionary<Key, Value>
could very well be all that you need. To me, 57,000 items doesn't really sound that much unless each row contains a huge amount of data. However, if you need to search by different columns, an in-memory database is most likely the way to go.