diff --git a/cms/one_time_startup.py b/cms/one_time_startup.py index cbd8775d97..4198cf2637 100644 --- a/cms/one_time_startup.py +++ b/cms/one_time_startup.py @@ -9,8 +9,11 @@ from django.core.cache import get_cache CACHE = get_cache('mongo_metadata_inheritance') for store_name in settings.MODULESTORE: store = modulestore(store_name) - store.metadata_inheritance_cache_subsystem = CACHE - store.request_cache = RequestCache.get_request_cache() + + store.set_modulestore_configuration({ + 'metadata_inheritance_cache_subsystem': CACHE, + 'request_cache': RequestCache.get_request_cache() + }) modulestore_update_signal = Signal(providing_args=['modulestore', 'course_id', 'location']) store.modulestore_update_signal = modulestore_update_signal diff --git a/common/lib/xmodule/xmodule/modulestore/__init__.py b/common/lib/xmodule/xmodule/modulestore/__init__.py index 17741225e5..a9848d6c05 100644 --- a/common/lib/xmodule/xmodule/modulestore/__init__.py +++ b/common/lib/xmodule/xmodule/modulestore/__init__.py @@ -384,6 +384,13 @@ class ModuleStore(object): """ raise NotImplementedError + def set_modulestore_configuration(self, config_dict): + ''' + Allows for runtime configuration of the modulestore. In particular this is how the + application (LMS/CMS) can pass down Django related configuration information, e.g. caches, etc. + ''' + raise NotImplementedError + class ModuleStoreBase(ModuleStore): ''' @@ -395,6 +402,7 @@ class ModuleStoreBase(ModuleStore): ''' self._location_errors = {} # location -> ErrorLog self.metadata_inheritance_cache = None + self.request_cache = None self.modulestore_update_signal = None # can be set by runtime to route notifications of datastore changes def _get_errorlog(self, location): @@ -439,6 +447,14 @@ class ModuleStoreBase(ModuleStore): return c return None + def set_modulestore_configuration(self, config_dict): + """ + This is the base implementation of the interface, all we need to do is store + two possible configurations as attributes on the class + """ + self.metadata_inheritance_cache = config_dict.get('metadata_inheritance_cache_subsystem', None) + self.request_cache = config_dict.get('request_cache', None) + def namedtuple_to_son(namedtuple, prefix=''): """ diff --git a/common/lib/xmodule/xmodule/modulestore/mixed.py b/common/lib/xmodule/xmodule/modulestore/mixed.py index 1ecb12f858..fe4d4d63be 100644 --- a/common/lib/xmodule/xmodule/modulestore/mixed.py +++ b/common/lib/xmodule/xmodule/modulestore/mixed.py @@ -100,7 +100,21 @@ class MixedModuleStore(ModuleStoreBase): return courses def get_course(self, course_id): + """ + returns the course module associated with the course_id + """ return self._get_modulestore_for_courseid(course_id).get_course(course_id) def get_parent_locations(self, location, course_id): + """ + returns the parent locations for a given lcoation and course_id + """ return self._get_modulestore_for_courseid(course_id).get_parent_locations(location, course_id) + + def set_modulestore_configuration(self, config_dict): + """ + This implementation of the interface method will pass along the configuration to all ModuleStore + instances + """ + for store in self.modulestores.values(): + store.set_modulestore_configuration(config_dict) diff --git a/lms/one_time_startup.py b/lms/one_time_startup.py index e10ec06685..2cd2077c4e 100644 --- a/lms/one_time_startup.py +++ b/lms/one_time_startup.py @@ -8,8 +8,10 @@ from django.core.cache import get_cache cache = get_cache('mongo_metadata_inheritance') for store_name in settings.MODULESTORE: store = modulestore(store_name) - store.metadata_inheritance_cache_subsystem = cache - store.request_cache = RequestCache.get_request_cache() + store.set_modulestore_configuration({ + 'metadata_inheritance_cache_subsystem': cache, + 'request_cache': RequestCache.get_request_cache() + }) if hasattr(settings, 'DATADOG_API'): dog_http_api.api_key = settings.DATADOG_API