Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
aaa383b8
Commit
aaa383b8
authored
11 years ago
by
Will Daly
Browse files
Options
Downloads
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
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/djangoapps/util/memcache.py
+2
-4
2 additions, 4 deletions
common/djangoapps/util/memcache.py
common/djangoapps/util/tests/test_memcache.py
+11
-1
11 additions, 1 deletion
common/djangoapps/util/tests/test_memcache.py
with
13 additions
and
5 deletions
common/djangoapps/util/memcache.py
+
2
−
4
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
This diff is collapsed.
Click to expand it.
common/djangoapps/util/tests/test_memcache.py
+
11
−
1
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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment