Asp.net - VS缓存的静态变量用于存储字典 [英] Asp.net - Caching vs Static Variable for storing a Dictionary

查看:239
本文介绍了Asp.net - VS缓存的静态变量用于存储字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个网上商店有很多部门和类别。它们存储在我们的数据库访问频率。

I am building a web-store with many departments and categories. They are stored in our database and accessed often.

我们正在使用URL重写内的商店生成一个查询等几乎每一个要求。我们还需要将数据频繁迭代产生的主力店菜单和部门的网页。

We are using URL rewriting so almost every request within the store generates a lookup. We also need to iterate over the data frequently to generate menus for the main store and the department pages.

此信息不会经常改变,所以我想我应该在数据库装载到一本字典,以加​​快信息检索。

This information will not change often so I'm thinking that I should load the database into a dictionary to speed up the information retrieval.

我知道标准的做法是将数据加载到应用程序缓存,但是我认为还有就是缓存期间发生系列化一定程度,并为大型数据结构我想的开销将是显著。

I know the standard practice is to load data into the application cache, however i assume that there is some level of serialization that occurs during caching, and for a large data-structure I'm thinking the overhead would be significant.

我对这个冲动是把字典在一个静态变量的相关类之一。不过,我想获得这方面的一些输入的输入。我是正确的思维,这种方法会更快?它是可怕的做法呢?有没有办法,我缺少一个更好的办法?

My impulse on this is to put the dictionary in a static variable in one of the related classes. I would however like to get some input input on this. Am I right in thinking that this method would be faster? Is it horrible practice? Is there a better way that I'm missing?

我似乎无法找到这么多的信息和我真的AP preciate任何信息可以共享。谢谢!

I can't seem to find much information on this and I'd really appreciate any information that you can share. Thanks!

推荐答案

的应用和高速缓存集合并不序列化传递到他们的对象,它们存储实际的参考。从检索缓存的对象不会是一个昂贵的操作,不管对象有多大。使用缓存对象始终坚持,除非你有一个很好的理由不,它只是很好的做法。

The Application and Cache collections do not serialize the objects you pass into them, they store the actual reference. Retrieving an object from Cache will not be an expensive operation, no matter how large the object is. Always stick with the Cache objects unless you have a very good reason not to, its just good practice.

值得一提的唯一的另一件事是要确保你想想多线程访问此集合。你会与一些严重的问题,最终非常快,如果你不正确地锁定

The only other thing worth mentioning is to make sure you think about multithreaded access to this collection. You're going to end up with some serious issues very quickly if you don't lock properly

这篇关于Asp.net - VS缓存的静态变量用于存储字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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