11

我正在寻找一种用于缓存大量数据的解决方案。

相关问题,但针对不同语言:

用不同的术语关闭问题:

我不需要(或不想为此支付任何费用)持久性、事务、线程安全等,并且想要使用不比 List<> 或 Dictionary<> 复杂得多的东西。

如果我必须编写代码,我会将所有内容保存为临时目录中的文件:

string Get(int i)
{
   File.ReadAllText(Path.Combine(root,i.ToString());
}

在我的情况下,索引将是一个int(并且它们应该是连续的或足够接近)并且数据将是一个string,因此我可以摆脱同时处理POD并且宁愿超轻并做到这一点。

用法是我有一个 3k 文件序列(如文件 #1 到 #3000),总计 650MB,需要为序列中的每个步骤做一个差异。我希望总数大致相同或更多,我不想将所有这些都保存在内存中(更大的情况可能会出现在我无法做到的情况下)。


许多人为我的问题提出了不同的解决方案。然而,似乎没有一个针对我的小利基。我正在查看磁盘支持缓存的原因是因为我预计我当前的使用将占用我可用地址空间的 1/3 到 1/2。我担心更大的箱子会完全耗尽空间。我不担心踩踏、持久性或复制。我正在寻找的是使用最少代码、最少占用空间、最少内存开销和最低复杂性的最小解决方案。

我开始认为我过于乐观了。

4

10 回答 10

4

What you really want is a B-Tree. That's the primary data structure that a database uses. It's designed to enable you to efficiently swap portions of a data structure to and from disk as needed.

I don't know of any widely used, high quality standalone B-Tree implementations for C#.

However, an easy way to get one would be to use a Sql Compact database. The Sql Compact engine will run in-process, so you don't need a seperate service running. It will give you a b-tree, but without all the headaches. You can just use SQL to access the data.

于 2009-01-03T02:07:24.960 回答
2

这与我的问题非常相似

在 C# 中寻找一个简单的独立持久字典实现

我认为不存在完全符合您想要的库,也许是时候在 github 上创建一个新项目了。

于 2009-01-04T22:20:54.197 回答
2

Disclaimer - I am about to point you at a product that I am involved in.

I'm still working on the web site side of things, so there is not a lot of info, but Serial Killer would be a good fit for this. I have examples that use .Net serialization (can supply examples), so writing a persistent map cache for .Net serializable objects would be trivial.

Enough shameless self promotion - if interested, use the contact link on the website.

于 2009-01-03T02:06:09.173 回答
1

这是 .net 的 B-Tree 实现:http: //bplusdotnet.sourceforge.net/

于 2009-03-03T04:56:27.117 回答
0

you can use the MS application block with disk based cache solution

于 2009-01-03T01:19:53.743 回答
0

Try looking at NCache here also.

I am not affiliated with this company. I've just downloaded and tested their free express version.

于 2009-01-03T02:00:42.430 回答
0

我已将 EhCache Java 应用程序部分弹出到 .NET 尚未实现分布式缓存,但在单个节点上,所有原始单元测试都通过了。完全开源:

http://sourceforge.net/projects/thecache/

如果您需要,我可以创建一个二进制文件(现在只有源代码可用)

于 2009-01-03T04:39:02.860 回答
0

鉴于您最近对该问题进行了编辑,我建议您实施问题中提到的解决方案,因为您不太可能找到包含在库中供您重用的如此幼稚的解决方案。

于 2009-01-03T23:33:33.317 回答
0

I'd take the embedded DB route (SQLite, Firebird), but here are some other options:

于 2009-01-03T05:48:53.733 回答
0

I recommend the Caching Application block in the Enterprise Library from MS. That was recommended as well, but the link points to an article on the Data Access portion of the Enterprise Library.

Here is the link to the Caching Application Block:

http://msdn.microsoft.com/en-us/library/cc309502.aspx

And specifically, you will want to create a new backing store (if one that persists to disk is not there):

http://msdn.microsoft.com/en-us/library/cc309121.aspx

于 2009-01-03T06:19:55.230 回答