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
b348f5d9
Commit
b348f5d9
authored
Mar 04, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache toolbox disabled
parent
98f5a79d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
25 deletions
+25
-25
courseware/models.py
+24
-24
student/models.py
+1
-1
No files found.
courseware/models.py
View file @
b348f5d9
...
@@ -14,12 +14,12 @@ ASSUMPTIONS: modules have unique IDs, even across different module_types
...
@@ -14,12 +14,12 @@ ASSUMPTIONS: modules have unique IDs, even across different module_types
"""
"""
from
django.db
import
models
from
django.db
import
models
from
django.db.models.signals
import
post_save
,
post_delete
from
django.db.models.signals
import
post_save
,
post_delete
from
django.core.cache
import
cache
#
from django.core.cache import cache
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
cache_toolbox
import
cache_model
,
cache_relation
#
from cache_toolbox import cache_model, cache_relation
CACHE_TIMEOUT
=
60
*
60
*
4
# Set the cache timeout to be four hours
#
CACHE_TIMEOUT = 60 * 60 * 4 # Set the cache timeout to be four hours
class
StudentModule
(
models
.
Model
):
class
StudentModule
(
models
.
Model
):
# For a homework problem, contains a JSON
# For a homework problem, contains a JSON
...
@@ -58,35 +58,35 @@ class StudentModule(models.Model):
...
@@ -58,35 +58,35 @@ class StudentModule(models.Model):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
module_type
+
'/'
+
self
.
student
.
username
+
"/"
+
self
.
module_id
+
'/'
+
str
(
self
.
state
)[:
20
]
return
self
.
module_type
+
'/'
+
self
.
student
.
username
+
"/"
+
self
.
module_id
+
'/'
+
str
(
self
.
state
)[:
20
]
@classmethod
#
@classmethod
def
get_with_caching
(
cls
,
student
,
module_id
):
#
def get_with_caching(cls, student, module_id):
k
=
cls
.
key_for
(
student
,
module_id
)
#
k = cls.key_for(student, module_id)
student_module
=
cache
.
get
(
k
)
#
student_module = cache.get(k)
if
student_module
is
None
:
#
if student_module is None:
student_module
=
StudentModule
.
objects
.
filter
(
student
=
student
,
#
student_module = StudentModule.objects.filter(student=student,
module_id
=
module_id
)[
0
]
#
module_id=module_id)[0]
# It's possible it really doesn't exist...
#
# It's possible it really doesn't exist...
if
student_module
is
not
None
:
#
if student_module is not None:
cache
.
set
(
k
,
student_module
,
CACHE_TIMEOUT
)
#
cache.set(k, student_module, CACHE_TIMEOUT)
return
student_module
#
return student_module
@classmethod
@classmethod
def
key_for
(
cls
,
student
,
module_id
):
def
key_for
(
cls
,
student
,
module_id
):
return
"StudentModule-student_id:{0};module_id:{1}"
.
format
(
student
.
id
,
module_id
)
return
"StudentModule-student_id:{0};module_id:{1}"
.
format
(
student
.
id
,
module_id
)
def
clear_cache_by_student_and_module_id
(
sender
,
instance
,
*
args
,
**
kwargs
):
#
def clear_cache_by_student_and_module_id(sender, instance, *args, **kwargs):
k
=
sender
.
key_for
(
instance
.
student
,
instance
.
module_id
)
#
k = sender.key_for(instance.student, instance.module_id)
cache
.
delete
(
k
)
#
cache.delete(k)
def
update_cache_by_student_and_module_id
(
sender
,
instance
,
*
args
,
**
kwargs
):
#
def update_cache_by_student_and_module_id(sender, instance, *args, **kwargs):
k
=
sender
.
key_for
(
instance
.
student
,
instance
.
module_id
)
#
k = sender.key_for(instance.student, instance.module_id)
cache
.
set
(
k
,
instance
,
CACHE_TIMEOUT
)
#
cache.set(k, instance, CACHE_TIMEOUT)
post_save
.
connect
(
update_cache_by_student_and_module_id
,
sender
=
StudentModule
,
weak
=
False
)
#
post_save.connect(update_cache_by_student_and_module_id, sender=StudentModule, weak=False)
post_delete
.
connect
(
clear_cache_by_student_and_module_id
,
sender
=
StudentModule
,
weak
=
False
)
#
post_delete.connect(clear_cache_by_student_and_module_id, sender=StudentModule, weak=False)
cache_model
(
StudentModule
)
#
cache_model(StudentModule)
student/models.py
View file @
b348f5d9
...
@@ -13,7 +13,7 @@ import uuid
...
@@ -13,7 +13,7 @@ import uuid
from
django.db
import
models
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
cache_toolbox
import
cache_model
,
cache_relation
#
from cache_toolbox import cache_model, cache_relation
class
UserProfile
(
models
.
Model
):
class
UserProfile
(
models
.
Model
):
class
Meta
:
class
Meta
:
...
...
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