ananthakumaran/memcachex

Dalli Compatibility

Opened this issue · 1 comments

Hello again!

Memcachex is not compatible with Dalli, even if both of them are using JSON as the serializer. The reason is that Dalli will only run the deserialize if a certain bit is set on the flags of the key. Here's the relevant code:

Only deseralize if bit is set:
https://github.com/petergoldstein/dalli/blob/master/lib/dalli/server.rb#L442

Set serialization bit if a serializer is used:
https://github.com/petergoldstein/dalli/blob/master/lib/dalli/server.rb#L435

I'm not entirely sure, but I think the fix would be to set that bit in the flags on the set, add, and replace commands (if a coder is specified).

What do you think?

achieving exact semantics as Dalli might be tricky. Currently, Connection module accepts the flag value, but the response headers are not exposed. We can proceed in multiple ways,

  1. add a :flag option similar to :ttl in Memcache module and pass it along to Connection module. You can manually set the flag & the correct coder. This still can't achieve full compatibility with dalli because the decoder will blindly decode it irrespective of the flag value. But this could be the done with less coding effort.

  2. add another method like execute in Connection module that exposes the reponse headers. Change the coder semantics such that encode can return a flag value and decode will be called with flag in addition to the value. This will provide full compatibility, but this might require more effort and might introduce breaking changes.