C#的磁盘备份词典/缓存 [英] Disk backed dictionary/cache for c#

查看:145
本文介绍了C#的磁盘备份词典/缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找解决方案中的一滴用于缓存肥胖型的数据

I'm looking for a drop in solution for caching large-ish amounts of data.

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

related questions but for different languages:

  • Python Disk-Based Dictionary
  • Disk-backed STL container classes?

关闭问题:

  • Looking for a simple standalone persistant dictionary implementation in C#

我不需要(或要支付任何东西)持久性,事务,线程安全性等,并且希望东西是不是要复杂得多列表<使用;>或字典<>

I don't need (or want to pay anything for) persistence, transactions, thread safety or the like and want something that is not much more complex to use than a List<> or Dictionary<>.

如果我必须写代码,我就关闭保存所有的文件在临时目录中:

If I have to write code, I'll just save everything off as files in the temp directory:

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

在我的情况下指数将是一个 INT (他们应该是连续的或非常接近),数据将是一个字符串这样我就可以逃脱治疗既有的POD 并宁愿去超轻,准确地做到这一点。

In my cases in index will be an int (and they should be consecutive or close enough) and the data will be a string so I can get away with treating both a POD and would rather go ultra-light and do exactly that.

用法我有3K文件的序列(如在文件#1到#3000)共计650MB和需要为序列中的每个步骤执行一个diff。我预计大约相同或者更多一点,我不希望将所有的内存(较大的情况下可能会沿着那里我只是不能)总。

The usage is that I have a sequence of 3k files (as in file #1 to #3000) totaling 650MB and need to do a diff for each step in the sequence. I expect that to total about the same or a little more and I don't want to keep all that in memory (larger cases may come along where I just can't).


许多人建议我的问题不同的解决方案。但是似乎没有在我的小利基有针对性。我期待在磁盘备份缓存的原因是因为我希望我目前使用会占用1/3到我的可用地址空间的1/2。我担心更大的情况下,将只平运行的空间。我并不担心踩,持续性或复制。我正在寻找的是用最少的代码,最小的用法脚印,在内存开销和最小的复杂性最小的一个最小的解决方案。

A number of people have suggested different solutions for my problem. However none seem to be targeted at my little niche. The reasons that I'm looking at disk backed caching is because I'm expecting that my current use will use up 1/3 to 1/2 of my available address space. I'm worried that larger cases will just flat run out of space. I'm not worried about treading, persistence or replication. What I'm looking for is a minimal solution using a minimum of code, a minimal usage foot print, minimal in memory overhead and minimum complexity.

我开始认为我过于乐观。

I'm starting to think I'm being overly optimistic.

推荐答案

您真正想要的是一个B树。
就是这样一个数据库使用的主要数据结构。
它的设计,根据需要启用您有效地交换数据结构的部分,并从磁盘上。

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.

我不知道有什么用途广泛,高质量独立b树的实现为C#。

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

但是,一个简单的方法,以得,一将使用SQL Compact数据库。在SQL紧凑型发动机将在进程内运行,所以你并不需要一个单独的服务运行。它会给你一个B-tree,但没有所有的头痛。你可以使用SQL来访问数据。

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.

这篇关于C#的磁盘备份词典/缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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