持久性方法大asp.net缓存存储效率 [英] Efficiency of persistence methods for large asp.net cache store

查看:174
本文介绍了持久性方法大asp.net缓存存储效率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果任何人有意见哪种方法会更适合asp.net缓存好奇。选择一,在缓存中的项目较少这是比较复杂的,或很多项目这是不太复杂的。

Curious if anyone has opinions on which method would be better suited for asp.net caching. Option one, have fewer items in the cache which are more complex, or many items which are less complex.

有关就事论事让我们来想象我的网站有销售员和客户对象。这些是pretty简单的类,但我并不想成为健谈与数据库,所以我想他们懒加载到缓存和无效出来缓存,当我做出改变 - 很简单

For sake of discussion lets imagine my site has SalesPerson and Customer objects. These are pretty simple classes but I don’t want to be chatty with the database so I want to lazy load them into cache and invalidate them out of the cache when I make a change – simple enough.

选项1
创建词典并缓存整个字典。当我需要加载从缓存中,我得到了字典营业员的实例,并执行针对字典正常的键查找。

Option 1 Create Dictionary and cache the entire dictionary. When I need to load an instance of a SalesPerson from the cache I get out the Dictionary and perform a normal key lookup against the Dictionary.

选项2
preFIX每个项目的键,并直接在asp.net缓存存储它。例如在高速缓存每个业务员实例将使用preFIX的复合加该对象的密钥,因此它可能看起来像以sp_ [GUID]及存储在asp.net缓存以及在高速缓存是对客户像cust_一个关键对象[GUID]

Option 2 Prefix the key of each item and store it directly in the asp.net cache. For example every SalesPerson instance in the cache would use a composite of the prefix plus the key for that object so it may look like sp_[guid] and is stored in the asp.net cache and also in the cache are the Customer objects with a key like cust_[guid].

我的一个恐惧与方案二是项目的数量将变得非常大,销售人员,客户和十几家其他类别之间我有可能在高速缓存25K项目和高度重复查找的是这样一个字符串的资源,我使用的几个地方,而code相通过缓存的领取钥匙找到它之间的其他25K可能支付违约金。

One of my fears with option two is that the numbers of entries will grow very large, between SalesPerson, Customer and a dozen or so other categories I might have 25K items in cache and highly repetitive lookups for something like a string resource that I am using in several places might pay a penalty while the code looks through the cache’s key collection to find it amongst the other 25K.

我可以肯定在某些时候是有报酬递减这里在缓存中存储太多的项目,但我很好奇,在这些问题上的意见。

I am sure at some point there is a diminishing return here on storing too many items in the cache but I am curious as to opinions on these matters.

推荐答案

您是在缓存中创建很多规模较小的项目,而不是创造更少,更大的项目最好关机。这里是一个道理:

You are best off to create many, smaller items in the cache than to create fewer, larger items. Here is the reasoning:

1)如果您的数据较小,则在高速缓存中的项目数将是相对小的,它不会有什么区别。从缓存中读取单一的实体比获取一本字典,然后从该字典中获取的项目,也更容易。

1) If your data is small, then the number of items in the cache will be relatively small and it won't make any difference. Fetching single entities from the cache is easier than fetching a dictionary and then fetching an item from that dictionary, too.

2)一旦你的数据变大,高速缓存可用于智能地管理数据。该HttpRuntime.Cache对象利用最近最少使用(LRU)算法来确定缓存项过期其中。如果只有少量的在高速缓存高度使用的物品,该算法将是无用的。但是,如果你在高速缓存中的许多较小的项目,但90%的人都没有在任何特定的时刻(很常见的用法启发式)使用,那么LRU算法可以保证那些看到积极利用项目保留在缓存中而驱逐较少使用的物品,以确保有足够的空间仍然是用过的。

2) Once your data grows large, the cache may be used to manage the data in an intelligent fashion. The HttpRuntime.Cache object makes use of a Least Recently Used (LRU) algorithm to determine which items in the cache to expire. If you have only a small number of highly used items in the cache, this algorithm will be useless. However, if you have many smaller items in the cache, but 90% of them are not in use at any given moment (very common usage heuristic), then the LRU algorithm can ensure that those items that are seeing active use remain in the cache while evicting less-used items to ensure sufficient room remains for the used ones.

随着应用程序的增长,是能够管理是什么在缓存将是最重要的的重要性。另外,我还没有看到从缓存中有上百万的密匙任何性能下降 - 哈希表是非常快,如果你发现有问题,它可能很容易改变你的命名约定为缓存键来优化它们用作解决哈希表的键。

As your application grows, the importance of being able to manage what is in the cache will be most important. Also, I've yet to see any performance degradation from having millions of keys in the cache -- hashtables are extremely fast and if you find issues there it's likely easily solved by altering your naming conventions for your cache keys to optimize them for use as hashtable keys.

这篇关于持久性方法大asp.net缓存存储效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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