﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20892	Allow configuring the memcached Client with CACHES 'OPTIONS'	alex@…	Ed Morley	"This appears to be an issue related to the fact that older releases of memcached insisted on a 1 MB value size limit.

Current releases of memcached have a user-configurable limit, however Django still uses a hard-wired 1 MB limit.

This (undocumented) 'feature' is currently causing errors, see the following two SO questions (one by me):

http://stackoverflow.com/questions/18143159/apparent-bug-storing-large-keys-in-django-memcached
http://stackoverflow.com/questions/11874377/django-caching-a-large-list

A 'solution' is proposed by the second SO question:

also edit this class in memcached.py located in /usr/lib/python2.7/dist-packages/django/core/cache/backends to look like this:
{{{#!python
class MemcachedCache(BaseMemcachedCache):
""An implementation of a cache binding using python-memcached""
def __init__(self, server, params):
    import memcache
    memcache.SERVER_MAX_VALUE_LENGTH = 1024*1024*10 #added limit to accept 10mb
    super(MemcachedCache, self).__init__(server, params,
                                         library=memcache,
                                         value_not_found_exception=ValueError)
}}}
Perhaps this could be added to the config of the logger?

For example, an ITEM_SIZE_MAX key could be created for the dictionary, so the following code could be used:
{{{#!python
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'ITEM_SIZE_MAX': 10,
        'LOCATION': 'localhost:11211',
    }
}
}}}

Obviously, the user would also have to add the necessary -I parameter to their /etc/memcached.conf (system dependent). I suppose the best would be if we could automatically detect the item size from their current memcached setup. For example:
{{{#!python
from subprocess import Popen, Pipe
memcached_call = Popen(""echo stats settings | nc localhost 11211"", stdout=PIPE, stderr=PIPE, shell=True)
out, err = memcached_call.communicate()
if err:
    log(""Error when getting memcached stats to find item size max: ""+err+""\n. Assuming max size is 1 MB"")
    maxsize_int = 1024*1024
else:
    values = out.split(""\n"")
    maxsize_field = filter(lambda field: field.startswith(""STAT item_size_max""), values)[0]
    maxsize_int = int(maxsize_field.strip()[maxsize_field.rindex("" ""):])
}}}

"	New feature	closed	Core (Cache system)	1.5	Normal	fixed		alex@… shai@… olavmrk@… emorley@…	Accepted	1	0	0	0	0	0
