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

308 Views Asked by At

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

There are 1 best solutions below

0
On

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