def load(self, filename, create_if_missing=True):
        filename = Path(filename)
        if not filename.exists() and create_if_missing:
            self.load_pip_requirements()
            with filename.open("w") as f:
                f.write(yaml.dump(self.serialized, default_flow_style=False,
                                  encoding=None))
            self.filename = filename
            return self.save(filename)
        with filename.open() as f:
            for group, requirements in yaml.load(f.read()).items():
                for requirement in requirements:
                    self[group].add(Requirement.coerce(requirement))
        self.filename = filename
def _get_or_create_cached_value(self, key, getter, ttl=None):
        # happy path
        try:
            expiry, value = self._cache[key]
        except KeyError:
            pass
        else:
            if expiry is None or time.time() < expiry:
                logger.debug("Key %s from cache", key)
                return value
            logger.debug("Cache for key %s has expired", key)

        # get value
        value = getter()
        if ttl:
            expiry = time.time() + ttl
        else:
            expiry = None
        self._cache[key] = (expiry, value)
        logger.debug("Set cache for key %s", key)

        return value