#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)
Change History (12)
comment:1 by , 16 years ago
Has patch: | set |
---|
comment:2 by , 16 years ago
Needs tests: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 16 years ago
Version: | 1.0 → SVN |
---|
comment:4 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 16 years ago
Attachment: | 10016-cache-middleware-handle-long-urls.diff added |
---|
comment:5 by , 16 years ago
Updated patch that generate key each form request.path everywhere it's use.
by , 16 years ago
Attachment: | 10016-handle-long-urls-with-tests.diff added |
---|
Updated patch (apply with -p1) to include tests for the new behavior.
comment:6 by , 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 , 16 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
Working on cleaning this up a little more per Jacob.
comment:8 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I've fix the problem by replacing request.path by an hash of request.path, see attached patch.