protected function getAllowedMethods(string $resource)
    {
        $cached = $this->cache['allowed_methods'][$resource] ?? null;
        if ($cached !== null) {
            return $cached;
        }

        $resource_data = $this->resources[$resource] ?? null;
        if ($resource_data === null) {
            throw new \DomainException("Invalid resource '$resource'");
        }

        $allow = $this->implemented_methods;

        $methods = (array) ($resource_data['methods'] ?? null);
        if (!empty($methods)) {
            $allow = array_intersect(
                $allow,
                array_merge($methods, ['OPTIONS'])
            );
        }

        $this->cache['allowed_methods'][$resource] = $allow;
        return $allow;
    }