Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
aaa383b8
Commit
aaa383b8
authored
May 07, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
safe_key() now hashes the prefix/version as well, just in case
these are configured to be too long in the settings.
parent
1b0b365f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
5 deletions
+13
-5
common/djangoapps/util/memcache.py
+2
-4
common/djangoapps/util/tests/test_memcache.py
+11
-1
No files found.
common/djangoapps/util/memcache.py
View file @
aaa383b8
...
...
@@ -41,11 +41,9 @@ def safe_key(key, key_prefix, version):
# Attempt to combine the prefix, version, and key
combined
=
":"
.
join
([
key_prefix
,
version
,
key
])
# If the total length is too long for memcache, hash the key
# and combine the parts again
# If the total length is too long for memcache, hash it
if
len
(
combined
)
>
250
:
key
=
fasthash
(
key
)
combined
=
":"
.
join
([
key_prefix
,
version
,
key
])
combined
=
fasthash
(
combined
)
# Return the result
return
combined
common/djangoapps/util/tests/test_memcache.py
View file @
aaa383b8
...
...
@@ -4,6 +4,7 @@ Tests for memcache in util app
from
django.test
import
TestCase
from
django.core.cache
import
get_cache
from
django.conf
import
settings
from
util.memcache
import
safe_key
...
...
@@ -51,8 +52,17 @@ class MemcacheTest(TestCase):
def
test_long_key_prefix_version
(
self
):
# Long key
key
=
safe_key
(
'a'
*
300
,
'prefix'
,
'version'
)
self
.
assertEqual
(
key
[
0
:
15
],
'prefix:version:'
)
self
.
assertTrue
(
self
.
_is_valid_key
(
key
))
# Long prefix
key
=
safe_key
(
'key'
,
'a'
*
300
,
'version'
)
self
.
assertTrue
(
self
.
_is_valid_key
(
key
))
# Long version
key
=
safe_key
(
'key'
,
'prefix'
,
'a'
*
300
)
self
.
assertTrue
(
self
.
_is_valid_key
(
key
))
def
test_safe_key_unicode
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment