MemcachedKeyLengthError for long keys

Issue #7 new
Anonymous created an issue

I am getting a "MemcachedKeyLengthError: Key length is > 250" exception being thrown for long keys.

After some investigating, I see the sanitize_memcached_key doing its job and creating a 250 character key. That then ends up being passed around and ends up in django.core.cache.backends.base.default_key_func which prepends at least a couple of characters (":1:" in the default case), making the actual key memcache sees too long: https://github.com/django/django/blob/master/django/core/cache/backends/base.py#L27

I don't see any way to pass in a different max key length, or configure the default. Would it be possible to add one or the other? Thanks.

Comments (3)

  1. Mikhail Korobov repo owner

    Hi @ggbaker,

    A good catch! When the project was started django didn't prepend that to cache keys. Maybe the proper fix would be to try figure out automatically how many chars is django prepending to the keys in a user's project.

    Unfortunately I haven't touched this project for years, as I'm currently not doing web development full time. Also, there is https://bitbucket.org/kmike/django-cache-utils/issue/3/can-not-cache-values-longer-than-300-sec issue which makes "group" support not so useful. If you are interested in reviving the development I can give you keys to the repo (ping me via email kmike84 at gmail.com); I don't have time to maintain this project myself.

  2. Log in to comment