Skip to content

Instantly share code, notes, and snippets.

@watchamcb
Last active February 18, 2016 09:02
Show Gist options
  • Save watchamcb/8625618560c94eafb3e7 to your computer and use it in GitHub Desktop.
Save watchamcb/8625618560c94eafb3e7 to your computer and use it in GitHub Desktop.
Python function to calculate overhead of Memcached items
def calc_max_data_len(chunk_size, key_length=0, cas_enabled=True):
max_data = chunk_size - (key_length + 1) # less null terminated key
max_data -= 48 # item overhead
if cas_enabled:
max_data -= 8 # bytes for cas
max_data -= 2 # data termination \r\n
max_data -= len(" 0 %d\r\n" % max_data) # max header with flags 0
return max_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment