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
88ff84dd
Commit
88ff84dd
authored
May 25, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a key function that is safe for use w/ memcache
parent
f632db0e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
3 deletions
+29
-3
envs/dev.py
+3
-1
envs/devplus.py
+2
-0
envs/static.py
+3
-1
envs/test.py
+3
-1
lib/util/memcache.py
+18
-0
No files found.
envs/dev.py
View file @
88ff84dd
...
...
@@ -31,7 +31,8 @@ CACHES = {
# In staging/prod envs, the sessions also live here.
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.locmem.LocMemCache'
,
'LOCATION'
:
'mitx_loc_mem_cache'
'LOCATION'
:
'mitx_loc_mem_cache'
,
'KEY_FUNCTION'
:
'util.memcache.safe_key'
,
},
# The general cache is what you get if you use our util.cache. It's used for
...
...
@@ -43,6 +44,7 @@ CACHES = {
'BACKEND'
:
'django.core.cache.backends.dummy.DummyCache'
,
'KEY_PREFIX'
:
'general'
,
'VERSION'
:
4
,
'KEY_FUNCTION'
:
'util.cache.memcache_safe_key'
,
}
}
...
...
envs/devplus.py
View file @
88ff84dd
...
...
@@ -30,12 +30,14 @@ CACHES = {
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.memcached.MemcachedCache'
,
'LOCATION'
:
'127.0.0.1:11211'
,
'KEY_FUNCTION'
:
'util.memcache.safe_key'
,
},
'general'
:
{
'BACKEND'
:
'django.core.cache.backends.memcached.MemcachedCache'
,
'LOCATION'
:
'127.0.0.1:11211'
,
'KEY_PREFIX'
:
'general'
,
'VERSION'
:
5
,
'KEY_FUNCTION'
:
'util.memcache.safe_key'
,
}
}
...
...
envs/static.py
View file @
88ff84dd
...
...
@@ -30,7 +30,8 @@ CACHES = {
# In staging/prod envs, the sessions also live here.
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.locmem.LocMemCache'
,
'LOCATION'
:
'mitx_loc_mem_cache'
'LOCATION'
:
'mitx_loc_mem_cache'
,
'KEY_FUNCTION'
:
'util.memcache.safe_key'
,
},
# The general cache is what you get if you use our util.cache. It's used for
...
...
@@ -42,6 +43,7 @@ CACHES = {
'BACKEND'
:
'django.core.cache.backends.dummy.DummyCache'
,
'KEY_PREFIX'
:
'general'
,
'VERSION'
:
4
,
'KEY_FUNCTION'
:
'util.memcache.safe_key'
,
}
}
...
...
envs/test.py
View file @
88ff84dd
...
...
@@ -54,7 +54,8 @@ CACHES = {
# In staging/prod envs, the sessions also live here.
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.locmem.LocMemCache'
,
'LOCATION'
:
'mitx_loc_mem_cache'
'LOCATION'
:
'mitx_loc_mem_cache'
,
'KEY_FUNCTION'
:
'util.memcache.safe_key'
,
},
# The general cache is what you get if you use our util.cache. It's used for
...
...
@@ -66,6 +67,7 @@ CACHES = {
'BACKEND'
:
'django.core.cache.backends.dummy.DummyCache'
,
'KEY_PREFIX'
:
'general'
,
'VERSION'
:
4
,
'KEY_FUNCTION'
:
'util.memcache.safe_key'
,
}
}
...
...
lib/util/memcache.py
0 → 100644
View file @
88ff84dd
"""
This module provides a KEY_FUNCTION suitable for use with a memcache backend
so that we can cache any keys, not just ones that memcache would ordinarily accept
"""
from
django.utils.hashcompat
import
md5_constructor
from
django.utils.encoding
import
smart_str
import
string
def
safe_key
(
key
,
key_prefix
,
version
):
safe_key
=
smart_str
(
key
)
for
char
in
safe_key
:
if
ord
(
char
)
<
33
or
ord
(
char
)
==
127
:
safe_key
=
safe_key
.
replace
(
char
,
'_'
)
if
len
(
safe_key
)
>
250
:
safe_key
=
md5_constructor
(
safe_key
)
return
":"
.
join
([
key_prefix
,
str
(
version
),
safe_key
])
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