Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#10016 closed (fixed)

Cache middleware with memcached can't handle long URLs

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

Description

Memcached has a hard limit of 250 characters for cache keys (cite). However, cache keys for the cache middleware (and associated view decorators) are of the form

   'views.decorators.cache.cache_page.%s.%s.%s' % (key_prefix, request.path, headers_hash)

(cite)

This means that if the combined length of settings.CACHE_MIDDLEWARE_KEY_PREFIX and request.path is over about 180 characters, you'll get failures. With cmemcache you get obscure server errors; the pure-Python memcached client throws MemcachedKeyLengthError.

Attachments (2)

10016-cache-middleware-handle-long-urls.diff (1.7 KB ) - added by Timothée Peignier 16 years ago.
10016-handle-long-urls-with-tests.diff (5.2 KB ) - added by mcroydon 16 years ago.
Updated patch (apply with -p1) to include tests for the new behavior.

Download all attachments as: .zip

Change History (12)

comment:1 by Timothée Peignier, 16 years ago

Has patch: set

I've fix the problem by replacing request.path by an hash of request.path, see attached patch.

comment:2 by Timothée Peignier, 16 years ago

Needs tests: set
Owner: changed from nobody to Timothée Peignier
Status: newassigned

comment:3 by Timothée Peignier, 16 years ago

Version: 1.0SVN

comment:4 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

by Timothée Peignier, 16 years ago

comment:5 by Timothée Peignier, 16 years ago

Updated patch that generate key each form request.path everywhere it's use.

by mcroydon, 16 years ago

Updated patch (apply with -p1) to include tests for the new behavior.

comment:6 by mcroydon, 16 years ago

Needs tests: unset

I'm not sure if it's worth noting that this is a change in internals (we're generating a key based on a hash of the path not the path itself). There may be some people coding against the existing behavior, but they are probably firmly in "you're mucking with internals so expect things to break" territory.

I also didn't know how to best deal with the really long line lengths in the asserts so I left them there. Feel free to clean that up as you best see fit.

comment:7 by mcroydon, 16 years ago

Owner: changed from Timothée Peignier to mcroydon
Status: assignednew

Working on cleaning this up a little more per Jacob.

comment:8 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [10335]) Fixed #10016: the cache middleware no longer vomits when handed long URLs. Thanks, Matt Croydon.

comment:9 by Jacob, 16 years ago

(In [10336]) [1.0.X] Fixed #10016: the cache middleware no longer vomits when handed long URLs. Thanks, Matt Croydon. Backport of r10335 from trunk.

comment:10 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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