evan/memcached — pull request #101 by flyerhzm (2012-07-21 08:05:52+00:00)
Title: extract encode/decode for further extension

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