NHibernate的哪个缓存用于WinForms应用程序 [英] NHibernate which cache to use for WinForms application

查看:82
本文介绍了NHibernate的哪个缓存用于WinForms应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个后端数据库(Oracle)的一个C#WinForms应用程序和使用的NHibernate的O / R映射。我想,以减少传播到数据库尽可能因为在这里的网络是很慢,所以我读到第二级缓存。我发现这相当不错的介绍,其中列出了以下可用缓存实现



我想知道的我应该用我的应用程序



<哪一个实现p >的缓存应该是简单的,它不应该显著减慢查询的第一次出现,它不应该花太多的内存加载执行程序集。 (!随着NHibernate和城堡,应用程序已经占用了80 MB的RAM)





  • 速度:用途微软速度这是所有类型的数据的高度可扩展的内存应用程序缓存

  • 流行:使用Bamboo.Prevalence作为缓存提供者。 Bamboo.Prevalence是一个.NET实现克劳斯Wuestefeld在Prevayler给生活带来的对象流行的概念。 Bamboo.Prevalence提供透明的对象持久化到确定性系统面向CLR。它提供了智能客户端应用程序缓存持续

  • SysCache:采用的System.Web.Caching.Cache作为缓存提供者。这意味着,你可以依靠ASP.NET缓存功能,了解它是如何工作

  • SysCache2:到NHibernate.Caches.SysCache类似,使用ASP.NET缓存。此提供程序还支持基于SQL依赖关系的到期,这意味着它可以配置一定的缓存区域时更改数据库的相关数据

  • 内存缓存自动失效:使用memcached的; memcached是一个高性能的,分布式内存对象缓存系统,在本质上通用的,但拟用于减少数据库负载,加快动态Web应用程序。基本上一个分布式哈希表

  • SharedCache:高性能,分布式和复制的内存对象缓存系统。看到这里,并在这里获得更多信息




我考虑迄今为:




  • 速度显得相当的重量级和矫枉过正(文件完全同意467 KB的硬盘空间,也没有测量它需要到目前为止,因为我没到RAM使其运行,见下文)

  • 患病率,至少在我的第一次尝试,放缓从我的查询〜0.5秒至约5秒,和缓存没有工作(见下文)

  • SysCache似乎是ASP.NET,而不是WinForms的。

  • 内存缓存和SharedCache似乎是分布式的场景。



哪一个你会建议我使用?有也将是一个内置的实现,这当然是非常轻便,但引用的文章告诉我,我的(...)不应该用于生产代码这个缓存提供者,但仅用于测试的。



除了这最适合成为我的情况我也遇到了一些问题与应用它们的问题:




  • 速度抱怨 dcacheClient而不是应用程序配置文件中指定的标签。在配置文件中指定有效的标签,的虽然我创造了一个组装app.config文件,并从的这篇文章


  • 患病率,如上面提到的,在很大程度上减慢我的第一个查询,在执行完全相同的查询接下来的时间,另一个选择是发送到数据库中。也许我应该外化这个话题到另一个岗位,我会做,如果有人告诉我,这绝对是不寻常的查询变慢了这么多他需要进一步的细节来帮助我。



解决方案

SysCache使用 ASP.NET缓存不仅因为它是唯一一个包含.NET 2.X / 3.X(.NET 4包括一个独立的System.Runtime.Caching组装)



它可以在桌面应用中使用没有任何问题(我使用它现在),它几乎不需要配置。



现在,你的记忆力考虑似乎是有点过这个世纪。没有机器附带小于1GB,在过去几年,大多数拥有2GB和8GB之间,所以80MB基本上是什么都没有。浏览器在我写这需要220MB。



缓存的非常的精华即将使用的资源(通常是内存,磁盘非常特殊的情况下),以减少一个较慢的(网络使用)


I have a C# WinForms application with a database backend (oracle) and use NHibernate for O/R mapping. I would like to reduce communication to the database as much as possible since the network in here is quite slow, so I read about second level caching. I found this quite good introduction, which lists the following available cache implementations.

I'm wondering which implementation I should use for my application.

The caching should be simple, it should not significantly slow down the first occurrence of a query, and it should not take much memory to load the implementing assemblies. (With NHibernate and Castle, the application already takes up to 80 MB of RAM!)

  • Velocity: uses Microsoft Velocity which is a highly scalable in-memory application cache for all kinds of data.
  • Prevalence: uses Bamboo.Prevalence as the cache provider. Bamboo.Prevalence is a .NET implementation of the object prevalence concept brought to life by Klaus Wuestefeld in Prevayler. Bamboo.Prevalence provides transparent object persistence to deterministic systems targeting the CLR. It offers persistent caching for smart client applications.
  • SysCache: Uses System.Web.Caching.Cache as the cache provider. This means that you can rely on ASP.NET caching feature to understand how it works.
  • SysCache2: Similar to NHibernate.Caches.SysCache, uses ASP.NET cache. This provider also supports SQL dependency-based expiration, meaning that it is possible to configure certain cache regions to automatically expire when the relevant data in the database changes.
  • MemCache: uses memcached; memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Basically a distributed hash table.
  • SharedCache: high-performance, distributed and replicated memory object caching system. See here and here for more info

My considerations so far were:

  • Velocity seems quite heavyweight and overkill (the files totally take 467 KB of disk space, haven't measured the RAM it takes so far because I didn't manage to make it run, see below)
  • Prevalence, at least in my first attempt, slowed down my query from ~0.5 secs to ~5 secs, and caching didn't work (see below)
  • SysCache seems to be for ASP.NET, not for winforms.
  • MemCache and SharedCache seem to be for distributed scenarios.

Which one would you suggest me to use? There would also be a built-in implementation, which of course is very lightweight, but the referenced article tells me that I "(...) should never use this cache provider for production code but only for testing."

Besides the question which fits best into my situation I also faced problems with applying them:

  • Velocity complained that "dcacheClient" tag not specified in the application configuration file. Specify valid tag in configuration file," although I created an app.config file for the assembly and pasted the example from this article.

  • Prevalence, as mentioned above, heavily slowed down my first query, and the next time the exact same query was executed, another select was sent to the database. Maybe I should "externalize" this topic into another post. I will do that if someone tells me it is absolutely unusual that a query is slowed down so much and he needs further details to help me.

解决方案

SysCache uses the "ASP.NET" cache only because it's the only one included with .NET 2.x/3.x (.NET 4 includes a separate System.Runtime.Caching assembly)

It can be used in desktop applications without any problems (I'm using it right now), and it requires almost no configuration.

Now, your memory considerations seem to be a little off with this century. No machine has shipped with less than 1GB in the past years, and most have between 2GB and 8GB, so 80MB is essentially nothing. The browser in which I'm writing this takes 220MB.

The very essence of caching is about using a resource (usually memory, disk in very particular cases) to reduce the usage of a slower one (network)

这篇关于NHibernate的哪个缓存用于WinForms应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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