简体   繁体   English

关于CacheManager的C#企业库缓存性能

[英]c# Enterprise library Caching performance about CacheManager

What is best way to use the Caching library in performance view. 在性能视图中使用缓存库的最佳方法是什么。 I have a lot of data in my db tables that i want to cache. 我的数据库表中有很多要缓存的数据。

Lets say i have 3 tables named. 可以说我有3个表命名。

  1. AssignmentHead 分配头
  2. AssignmentRow 作业行
  3. Items 物品

Today iam storing the tables as fallows: 今天,iam将表存储为休假:

private CacheManager _manager = _manager = CacheFactory.GetCacheManager();

I'm having one CacheManger and i stores the data like this. 我有一个CacheManger,我存储这样的数据。

_manager.add("Heads",ListofAssignmentHeads);
_manager.add("Rows",ListofAssigmmentRows);
_manager.add("Items",ListOfItems);

When retrieving data like Heads i do fallowing: 当检索像Heads这样的数据时,我会休假:

_manager.GetData("Heads");

Then i'm getting a list of heads and using linq to query what i want. 然后我得到一个负责人的名单,并使用linq查询我想要的东西。 But is this the best way of doing this or is it better to set up 3 CacheManager for each table and insert the primary key and then the object. 但这是最好的方法,还是为每个表设置3个CacheManager并插入主键,然后插入对象更好。

_headManager.add("1",HeadObject);

I really need your advises on these one. 我真的需要您提供有关这方面的建议。 Thanks for the help. 谢谢您的帮助。

Personally, all things being almost equal, I would cache the data in the format that I will need it at runtime. 就个人而言,在几乎所有事物都相等的情况下,我将以运行时所需的格式缓存数据。 That way you can just get the information you need directly in the representation that you need. 这样,您就可以直接在所需的表示形式中获取所需的信息。 In your example that would be multiple CacheManagers with the primary key as the cache key. 在您的示例中,将有多个以主键为缓存键的CacheManager。

It looks like you already have methods that return the lists and you are caching the lists. 看起来您已经具有返回列表的方法,并且正在缓存列表。 I would rather iterate over the list once when the data is loaded and then perform a lookup by key than iterate the list on every call. 我宁愿在加载数据时对列表进行一次遍历,然后通过键执行查找,而不是在每次调用时对列表进行遍历。 If your lists are large you may see a performance hit if you have to search the lists for every request since finding the element in the list is O(N) vs. O(1) for a cache with no hash collisions. 如果列表很大,则必须为每个请求搜索列表,这可能会降低性能,因为找到列表中的元素是O(N)vs.O(1)来查找没有哈希冲突的缓存。

Of course, if you want to support dynamic lists then you might prefer to add lists as needed to a single CacheManager since creating dynamic CacheManagers is a bit of work. 当然,如果要支持动态列表,则可能需要根据需要向单个CacheManager添加列表,因为创建动态CacheManager有点麻烦。

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

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