def from_config(cls, config_dict, merge_default=True): """ Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments. :param config_dict: JSON compliant dictionary encapsulating a configuration. :type config_dict: dict :param merge_default: Merge the given configuration on top of the default provided by ``get_default_config``. :type merge_default: bool :return: Constructed instance from the provided config. :rtype: MemoryKeyValueStore """ # Copy top-level of config in order to not modify input instance. c = config_dict.copy() # Simplify specification for "no cache element" if 'cache_element' not in c or \ c['cache_element'] is None or \ c['cache_element']['type'] is None: c['cache_element'] = None else: # Create from nested config. c['cache_element'] = \ from_plugin_config(config_dict['cache_element'], get_data_element_impls()) return super(MemoryKeyValueStore, cls).from_config(c)
def get_config(self): # Recursively get config from data element if we have one. if hasattr(self._cache_element, 'get_config'): elem_config = to_plugin_config(self._cache_element) else: # No cache element, output default config with no type. elem_config = make_config(get_data_element_impls()) return {'cache_element': elem_config}
def get_config(self): # Recursively get config from data element if we have one. if hasattr(self._cache_element, 'get_config'): elem_config = to_plugin_config(self._cache_element) else: # No cache element, output default config with no type. elem_config = make_config(get_data_element_impls()) return { 'cache_element': elem_config }
def get_default_config(cls): """ Generate and return a default configuration dictionary for this class. This will be primarily used for generating what the configuration dictionary would look like for this class without instantiating it. It is not be guaranteed that the configuration dictionary returned from this method is valid for construction of an instance of this class. :return: Default configuration dictionary for the class. :rtype: dict """ default = super(MemoryKeyValueStore, cls).get_default_config() default['cache_element'] = make_config(get_data_element_impls()) return default