如何从ASP.NET Mvc的数据库中缓存大量数据 [英] How to Cache a large amount of data from database for ASP.NET Mvc

查看:443
本文介绍了如何从ASP.NET Mvc的数据库中缓存大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站使用linq-to-sql从数据库加载约5万行数据.该数据是静态的,永远不会改变.它的工作原理类似于垃圾邮件过滤器,并且需要加载所有50k行的模式.

My website uses linq-to-sql to load about 50k rows of data from a database. This data is static and never changes. It works similar to a spam filter and all 50k rows of patterns need to be loaded.

对此进行编程的最佳方法是什么?以获得最佳性能?

What's the best way to program this? for optimal performance?

推荐答案

将整个内容加载到单个静态只读数据结构中(它是不可变的,意味着一旦构建,便可以在许多线程中安全地使用它)将提供最大的整体效果每次查询的效果.

Loading the entire thing into a single static readonly data-structure (it being immutable means once constructed it can be safely used from many threads) would give the greatest overall performance per lookup.

但是,这将导致启动时间过长,这可能是不可接受的.在这种情况下,您可以考虑按访问方式加载每个项目,但这会带来并发问题(因为您正在更改多个线程使用的数据结构).

However, it would lead to a long start-up time, which may not be acceptable. In that case you may consider loading each item as accessed, but that brings concurrency issues (since you are mutating a data-structure used by multiple threads).

介于两者之间的选项是在启动时加载所有索引,然后在每次访问的基础上添加其余信息,并使用更细粒度的锁来减少锁争用.

In between is the option of loading all indices on start-up, and then adding the rest of the information on a per-access basis, with finer-grained locks to reduce lock contention.

或者您可以忽略很多,仅根据需要从数据库中加载.就性能而言,这确实具有一些优势,只是因为内存不用于很少使用的信息.如果您突然发现确实必须允许数据更改,那将容易得多.

Or you can ignore the lot and just load from the database as needed. This does have some advantages in terms of performance just because memory is not used for rarely-used information. It'll be a whole lot easier if you ever suddenly find that you do have to allow the data to change.

没有人会成为普遍可行的唯一合理方法,它取决于应用程序,数据和使用模式的细节.

No one comes out as the only reasonable way to go in general, it'll depend on specifics of application, data, and usage patterns.

这篇关于如何从ASP.NET Mvc的数据库中缓存大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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