def _parameters_up_to_date(self): """ Internal method that checks generator and non-generator parameters for being up-to-date. :return: True if no update is needed, otherwise False """ needs_update = not self._cache_matches_current() if not needs_update: for parameter in self._current_parameters.values(): if isinstance(parameter, parsimony.generators.Generator): needs_update |= not parameter.up_to_date() or parsimony.dirty(parameter.key()) return not needs_update
def generate(self): """Generate the object referred to by the key. If the object has never been generated before, the necessary work to create it is performed and the object is cached in a ParameterStore. If the object has been generated and the parameters have not been changed, the Generator checks for an in memory version of the object first and returns it. If not in memory, the generated object is retrieved from a ParameterStore and cached in memory, then returned. If the object has been generated, but the parameters have changed, the object is regenerated and the ParameterStore is overwritten. :return generated_value: The value for this generator's key. """ # regenerate if# # parameters have changed # did not exist in keys # generator parameters needed updated dirty = parsimony.dirty(self._key) if dirty: self._generated = False self._generated_value = None try: del self._cache[self._key] except KeyError: pass # throw all other errors, but a key error just means we weren't cached yet if (self._key in self._cache) and self._parameters_up_to_date() and self.up_to_date() and not dirty: if not self._generated: self._generated_value = self.load() self._generated = True else: for parameter, value in self._current_parameters.items(): if not isinstance(value, parsimony.generators.Generator): self._cache.update(self._cache_keys[parameter], self._obfuscator.obfuscate(value)) self._update_parameters() # parameters update needs to happen after storage since Generators get replaced self._generated_value = self.rebuild() self.dump(self._generated_value) self._generated = True self._cache.update(self._key, self._obfuscator.obfuscate(GENERATOR_DEFAULT_STORE_VALUE), list(self._cache_keys.values())) parsimony.clean(self._key) return self._generated_value