简体   繁体   English

IIS6 ASP.NET 2.0 应用程序缓存 - 大量数据的数据存储选项和性能

[英]IIS6 ASP.NET 2.0 Application Cache - data storage options and performance for large amounts of data

In an ASP.NET 2.0 site on IIS6 I would like to store Key / Value pairs in the Application Cache.IIS6上的 ASP.NET 2.0 站点中,我想将键/值对存储在应用程序缓存中。 Each Key will always be a string with a 5 character length and each Value a string of 15 - 250 characters length.每个 Key 始终是一个长度为 5 个字符的字符串,每个 Value 是一个长度为 15 - 250 个字符的字符串。

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.使用场景是每个网页请求都会查询一次缓存,如果存在密钥,则使用值,否则查询数据库并根据某些应用程序逻辑向缓存添加新的密钥/值或替换现有条目。

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.在这种情况下,我设想/要求缓存大小达到大约 1000 个条目,在该大小时它将变得稳定并且很少(如果有的话)如上所述进行更改。

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) Use 1 Cache object containing a SortedDictionary<string, string> or (1) 使用包含SortedDictionary<string, string>的 1 个缓存 object 或

(2) allow the creation of 1,000 Cache objects and the use the Cache itself as a dictionary or (2) 允许创建 1,000 个 Cache 对象并将 Cache 本身用作字典或

(3) It just doesn't matter for the amount of data in question. (3) 所讨论的数据量无关紧要。 In which case would your answer change if the number of entries increased to 10,000 or 100,000?如果条目数增加到 10,000 或 100,000,在哪种情况下您的答案会改变?

Many Thanks.非常感谢。

1000 is not a large amount of data; 1000不是大数据量; 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.实际上,访问Dictionary<string,string>lock可能很好,但如果需要,您可以更细粒度。

However, the inbuilt web cache ( HttpContext.Cache ) will also approach this same problem, and has all the thread-safety built in.然而,内置的 web 缓存 ( HttpContext.Cache ) 也会解决同样的问题,并且内置了所有线程安全。

Don't use SortedDictionary<,> unless you have a care that the data is sorted.不要使用SortedDictionary<,>除非您关心数据是否已排序。 I don't think you do.我不认为你这样做。

As numbers get larger, I'd be more inclined to think about stores such as redis / memcached, with local memory as a local shortcut.随着数字越来越大,我更倾向于考虑 redis / memcached 等存储,将本地 memory 作为本地快捷方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM