NHibernate MemCached with Protobuf-net.Enyim - does this really work?
I used the following assemblies to hook up NHibernate L2 caching with Enyim Memcached using the Protobuf-net binary serializer:
- NHibernate
- NHibernate.Caches.EnyimMemcached
- Enyim.Caching
- Protobuf network
- Protobuf-net.Enyim
[Serializable]
and neither
[DataContract]
, nor
[ProtoContract]
with the corresponding ordered data / ProtoMembers for properties. I can get protobuf-net to work with EnyimMemcached when interacting with memcache immediately after adding the appropriate attributes (or register them manually with the RuntimeTypeModel.Default protobuf-net class).
However, even if I do proper validation when registering my types with protobuf-net, I don't think that the cache entry coming from NHibernate will actually be serialized by protobuf-net because NHibernate.Caches.EnyimMemcached stores the cache entries in objects DictionaryEntry
:
bool returnOk = client.Store(
StoreMode.Set, KeyAsString(key),
new DictionaryEntry(GetAlternateKeyHash(key), value),
TimeSpan.FromSeconds(expiry));
DictionaryEntry
has no attributes [DataContract]
and [DataMember(Order = xx)]
. It makes me think ...
Can the protobuf-net serializer be used correctly for NHibernate's level 2 caching?
source to share
Since no one answered your question, I might as well give my two bits here. I don't know much about Memcached as a L2 cache, but there are powerful caching solutions that require minimal code changes to begin using as a L2 cache, and serialization is handled by the cache. You can use NCache as layer 2 cache for NHibernate
source to share