memcachex
memcachex copied to clipboard
Dalli Compatibility
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,
-
add a
:flagoption similar to:ttlinMemcachemodule and pass it along toConnectionmodule. 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. -
add another method like
executeinConnectionmodule 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.