NHibernate MemCached w/ Protobuf-net.Enyim — does it actually work?

谁说我不能喝 提交于 2019-12-11 04:09:11

问题


I've used the following assemblies to hook up NHibernate 2nd-level caching with Enyim Memcached using Protobuf-net binary serializer:

  • NHibernate
  • NHibernate.Caches.EnyimMemcached
  • Enyim.Caching
  • protobuf-net
  • protobuf-net.Enyim

It's recently come to my attention that despite hooking up protobuf-net with EnyimMemcached, I'm likely not actually using that serializer as all my entities were marked with just [Serializable] and neither [DataContract] or [ProtoContract] with corresponding ordered Data/ProtoMembers for the properties. I can get protobuf-net to work with EnyimMemcached when I interact with the memcache directly after I add the appropriate attributes (or register them manually with the RuntimeTypeModel.Default class of protobuf-net).

However, even if I do the due-diligence with registering my types with protobuf-net, I don't think any cache entry coming from NHibernate will actually be serialized by protobuf-net because NHibernate.Caches.EnyimMemcached stores entries in the cache within DictionaryEntry objects:

bool returnOk = client.Store(
    StoreMode.Set, KeyAsString(key),
    new DictionaryEntry(GetAlternateKeyHash(key), value),
    TimeSpan.FromSeconds(expiry));

DictionaryEntry does not have [DataContract] and [DataMember(Order = xx)] attributes. This makes me wonder...

Can I even properly utilize the protobuf-net serializer for NHibernate 2nd level caching?


回答1:


Since no one has answered your question, I might as well give my two bits in here. I don't know much about Memcached as a 2nd level cache but there are powerful caching solutions out there that require minimal code changes to start using as a level 2 cache and serialization is handled by the cache. You can use NCache as a level 2 cache for NHibernate



来源:https://stackoverflow.com/questions/15959821/nhibernate-memcached-w-protobuf-net-enyim-does-it-actually-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!