Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#11270 closed (fixed)

Cache templatetag with memcached can't handle long tags

Reported by: 235 Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

similar to #10016
Memcached has a hard limit of 250 characters for cache keys.

So we have to use md5 hash instead of the whole cached tag name with all vary variables.

Traceback (most recent call last):

  File "/var/www/virtual/sumno.com/modules/django/core/handlers/base.py", line 86, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/var/www/virtual/sumno.com/htdocs/sumnocom/apps/lib/decorators.py", line 56, in wrapper
    return func(request, *args, **kwargs)

  File "/var/www/virtual/sumno.com/htdocs/sumnocom/../sumnocom/apps/generic_content/views.py", line 370, in detail_view_content_entry
    context_instance=RequestContext(request))

  File "/var/www/virtual/sumno.com/modules/django/shortcuts/__init__.py", line 18, in render_to_response
    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

  File "/var/www/virtual/sumno.com/modules/django/template/loader.py", line 107, in render_to_string
    return t.render(context_instance)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 176, in render
    return self.nodelist.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 768, in render
    bits.append(self.render_node(node, context))

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 781, in render_node
    return node.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/loader_tags.py", line 97, in render
    return compiled_parent.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 176, in render
    return self.nodelist.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 768, in render
    bits.append(self.render_node(node, context))

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 781, in render_node
    return node.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/loader_tags.py", line 97, in render
    return compiled_parent.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 176, in render
    return self.nodelist.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 768, in render
    bits.append(self.render_node(node, context))

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 781, in render_node
    return node.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/loader_tags.py", line 24, in render
    result = self.nodelist.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 768, in render
    bits.append(self.render_node(node, context))

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 781, in render_node
    return node.render(context)

  File "/var/www/virtual/sumno.com/htdocs/sumnocom/apps/lib/templatetags/smartspaceless.py", line 17, in render
    s = self.nodelist.render(context).strip()

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 768, in render
    bits.append(self.render_node(node, context))

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 781, in render_node
    return node.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/loader_tags.py", line 24, in render
    result = self.nodelist.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 768, in render
    bits.append(self.render_node(node, context))

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 781, in render_node
    return node.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/loader_tags.py", line 24, in render
    result = self.nodelist.render(context)

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 768, in render
    bits.append(self.render_node(node, context))

  File "/var/www/virtual/sumno.com/modules/django/template/__init__.py", line 781, in render_node
    return node.render(context)

  File "/var/www/virtual/sumno.com/modules/django/templatetags/cache.py", line 27, in render
    value = cache.get(cache_key)

  File "/var/www/virtual/sumno.com/modules/django/core/cache/backends/memcached.py", line 25, in get
    val = self._cache.get(smart_str(key))

  File "/var/lib/python-support/python2.5/memcache.py", line 619, in get
    check_key(key)

  File "/var/lib/python-support/python2.5/memcache.py", line 885, in check_key
    % SERVER_MAX_KEY_LENGTH)

MemcachedKeyLengthError: Key length is > 250

Attachments (1)

cache_templatetag.patch (1.1 KB ) - added by 235 16 years ago.
django/templatetags/cache.py patch

Download all attachments as: .zip

Change History (7)

by 235, 16 years ago

Attachment: cache_templatetag.patch added

django/templatetags/cache.py patch

comment:1 by Chris Beaven, 16 years ago

milestone: 1.1
Needs tests: set
Triage Stage: UnreviewedAccepted

If Jacob thought #10016 was 1.1 worthy, this should be too.

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: newclosed

(In [11067]) Fixed #11270 -- Corrected naming conflict in templatetag test. Thanks to steveire for the report.

comment:3 by Russell Keith-Magee, 16 years ago

(In [11068]) Fixed #11270 -- Modified cache template tag to prevent the creation of very long cache keys. Thanks to 235 for the report and patch.

comment:4 by Russell Keith-Magee, 16 years ago

Please ignore the commit message for [11067] - that commit should have referenced #11289.

comment:5 by Russell Keith-Magee, 16 years ago

(In [11070]) [1.0.X] Fixed #11270 -- Modified cache template tag to prevent the creation of very long cache keys. Thanks to 235 for the report and patch.

Merge of r11068 from trunk.

comment:6 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top