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?