NHibernate 和 Memcached - 教程/示例
我安装了带有几个存储桶设置的 Membase 服务器,并且我正在寻找一个很好的教程或示例来说明如何将其用作 NHibernate 的二级缓存。
我对示例配置的外观感兴趣,以及是否需要在代码中执行任何操作,或者我是否可以通过 NHibernate 映射来处理所有这些内容。
感谢您的任何帮助。
I have the Membase server installed with a couple buckets setup and I was looking for a good tutorial or example of how to use this as the 2nd level cache with NHibernate.
I am interested in what a sample configuration would look like and if there is anything I need to do in code or if I can handle it all from my NHibernate mappings.
Thanks for any assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在映射文件中,您需要包含以下属性:
选项为读写(读提交隔离)、非严格读写(很少写入的对象、性能更好,但增加了陈旧数据的机会)或只读(永不改变的数据)。
然后,在您的 Web(或应用程序)配置中,您需要一个部分来配置 memcached:
最后,在您的会话工厂配置中,请务必使用:
当然,您需要从适当版本的 NHibernate.Caches 以获得正确的缓存提供程序。 memcached 也依赖于 ICSharpCode.SharpZipLib 和 Memcached.ClientLibrary(s/b 包含在下载中)
如果您使用的是流畅的 NHibernate,则会话工厂的设置链中有一个 .Cache 方法,您可以使用它使用,但某些属性需要通过调用 .ExposeConfiguration 手动设置。
In your mapping files, you will need to include the property:
Options are read-write (read committed isolation), nonstrict-read-write (objects that are rarely written, better performance but increased chance of stale data), or read-only (data that never changes).
Then, in your web (or app) config you need a section to configure memcached:
Finally, in your session factory configuration be sure to use:
Of course you will need to download and reference a dll from the appropriate version of NHibernate.Caches to get the right cache provider. The memcached one takes a dependency on ICSharpCode.SharpZipLib and Memcached.ClientLibrary as well (s/b included in the download)
If you're using fluent NHibernate, there is a .Cache method in the setup chain for a session factory that you can use, though some of the properties need to be set manually through a call to .ExposeConfiguration.