arthurnn / memcached

A Ruby interface to the libmemcached C client
Academic Free License v3.0
432 stars 125 forks source link

extract encode/decode for further extension #101

Closed flyerhzm closed 11 years ago

flyerhzm commented 12 years ago

we want to compress/decompress data using zlib and change memcached flags to 1

current implementation makes it difficult to extend and make use of flags, so I extract encode/decode methods, and extend them in my rails project, like

def encode_with_compressed(value, marshal, flags) value = encode_without_compressed(value, marshal, flags) flags & (flags & FLAG_COMPRESSED) == 0 ? value : Zlib::Deflate.deflate(value) end alias_method_chain :encode, :compressed

def decode_with_compressed(value, marshal, flags) value = (flags & FLAG_COMPRESSED) == 0 ? value : Zlib::Inflate.inflate(value) decode_without_compressed(value, marshal, flags) end alias_method_chain :decode, :compressed

flyerhzm commented 12 years ago

I also add ext/libmemcached-0.32/m4/aclocal.m4, which is existed in the memcached gem, but not in master branch.

evan commented 12 years ago

This is pretty ok but I don't want it to impact performance at all in the uncompressed case. So I think we should implement codec modules with encode/decode methods. If marshal=true (should change that variable name to encode), then the codec is called, otherwise the entire method dispatch is short-circuited like is currently the case.

Then turning on the codec still semantically allows for the possible that it doesn't actually encode, based on the flags, like you want.

Does that make sense?

This would be the biggest API change in the core class in 2 years. :-)

evan commented 11 years ago

Fixed by #118