IIS6 ASP.NET 2.0应用程序缓存 - 数据存储选项和性能,大量数据 [英] IIS6 ASP.NET 2.0 Application Cache - data storage options and performance for large amounts of data
问题描述
在ASP.NET 2.0网站上的 IIS6 我想用来存储键/值对在应用程序缓存。每个键将永远是一个5个字符长度的字符串,每个值15的字符串 - 250个字符长度
In an ASP.NET 2.0 site on IIS6 I would like to store Key / Value pairs in the Application Cache. Each Key will always be a string with a 5 character length and each Value a string of 15 - 250 characters length.
的使用情况是,缓存将被一次查询每个网页请求时,如果该键存在利用价值,否则查询数据库,要么添加一个新的键/值对缓存或更换基于一些应用程序逻辑的现有条目。
The usage scenario is that the Cache will be queried once per webpage request, if the Key exists use the Value otherwise query a database and either add a new Key / Value to the Cache or replace an existing entry based upon some application logic.
在这种情况下我设想/所需要的高速缓存大小达到大约1000个条目在哪些尺寸就会变得稳定,很少会(如果有的话),如上所述来改变。
In this scenario I envisage / require the Cache size to reach circa 1000 entries at which size it will become stable and will rarely (if at all) be changed as described above.
在我刚的性能测试自己没有任何人有大量的缓存数据,至于是否是最好的性能的经验于:
Before I just "performance test it myself" does anyone have any experience of large amounts of Cached data as to whether it is preferable for Performance to:
(1)使用含1缓存对象的 SortedDictionary<字符串,字符串>
或
(1) Use 1 Cache object containing a SortedDictionary<string, string>
or
(2)允许创建1000高速缓存对象和使用高速缓存本身作为字典的或
(2) allow the creation of 1,000 Cache objects and the use the Cache itself as a dictionary or
(3)在只是无关紧要为相关的数据量。在这种情况下,将你的答案改变,如果条目的数量增加至10000或10万?
(3) It just doesn't matter for the amount of data in question. In which case would your answer change if the number of entries increased to 10,000 or 100,000?
非常感谢。
推荐答案
1000不是一个大数据量;这将正常工作,但您将需要如果此数据被请求之间共享去想同步。在现实中锁定
进行访问词典<字符串,字符串>
可能是罚款,但你可以更细粒度的,如果你需要的。
1000 is not a large amount of data; that will work fine, but you will need to think about synchronization if this data is shared between requests. In reality a lock
to make access to a Dictionary<string,string>
is probably fine, although you can be more fine-grained if you need.
不过,内置的Web缓存( HttpContext.Cache
)也将接近这个。同样的问题,并已全部线程安全的内置
However, the inbuilt web cache (HttpContext.Cache
) will also approach this same problem, and has all the thread-safety built in.
不要使用 SortedDictionary<,>
除非你有一个数据排序的照顾。我不认为你做的。
Don't use SortedDictionary<,>
unless you have a care that the data is sorted. I don't think you do.
随着数字变大,我会更倾向于认为有关商店,如Redis的/ memcached的,以本地内存作为本地快捷键。
As numbers get larger, I'd be more inclined to think about stores such as redis / memcached, with local memory as a local shortcut.
这篇关于IIS6 ASP.NET 2.0应用程序缓存 - 数据存储选项和性能,大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!