class Policy:
    def __init__(self, flags=None):
        self.flags = dict(flags or {})
        self._decision_cache = {}

    def set_flag(self, name, enabled):
        self.flags[name] = bool(enabled)

    def allows(self, user_id, flag):
        key = (user_id, flag)
        if key not in self._decision_cache:
            self._decision_cache[key] = bool(self.flags.get(flag, False))
        return self._decision_cache[key]
