2

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?

4

1 回答 1

0

由于没有人回答您的问题,我不妨在这里给出我的两点。我对 Memcached 作为二级缓存知之甚少,但市面上有强大的缓存解决方案,它们需要最少的代码更改才能开始用作二级缓存,并且序列化由缓存处理。您可以将NCache 用作 NHibernate 的 2 级缓存

于 2013-05-21T11:35:15.360 回答