Commit 5e8e31b2 by Ned Batchelder

Add a cache attribute to ModuleSystem

parent ceb6ceda
...@@ -700,7 +700,9 @@ class ModuleSystem(object): ...@@ -700,7 +700,9 @@ class ModuleSystem(object):
anonymous_student_id='', anonymous_student_id='',
course_id=None, course_id=None,
open_ended_grading_interface=None, open_ended_grading_interface=None,
s3_interface=None): s3_interface=None,
cache=None,
):
''' '''
Create a closure around the system environment. Create a closure around the system environment.
...@@ -742,6 +744,11 @@ class ModuleSystem(object): ...@@ -742,6 +744,11 @@ class ModuleSystem(object):
xblock_model_data - A dict-like object containing the all data available to this xblock_model_data - A dict-like object containing the all data available to this
xblock xblock
cache - A cache object with two methods:
.get(key) returns an object from the cache or None.
.set(key, value, timeout_secs=None) stores a value in the cache with a timeout.
''' '''
self.ajax_url = ajax_url self.ajax_url = ajax_url
self.xqueue = xqueue self.xqueue = xqueue
...@@ -766,6 +773,8 @@ class ModuleSystem(object): ...@@ -766,6 +773,8 @@ class ModuleSystem(object):
self.open_ended_grading_interface = open_ended_grading_interface self.open_ended_grading_interface = open_ended_grading_interface
self.s3_interface = s3_interface self.s3_interface = s3_interface
self.cache = cache or DoNothingCache()
def get(self, attr): def get(self, attr):
''' provide uniform access to attributes (like etree).''' ''' provide uniform access to attributes (like etree).'''
return self.__dict__.get(attr) return self.__dict__.get(attr)
...@@ -779,3 +788,12 @@ class ModuleSystem(object): ...@@ -779,3 +788,12 @@ class ModuleSystem(object):
def __str__(self): def __str__(self):
return str(self.__dict__) return str(self.__dict__)
class DoNothingCache(object):
"""A duck-compatible object to use in ModuleSystem when there's no cache."""
def get(self, key):
return None
def set(self, key, value, timeout=None):
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment