public function applyConstraints($instance, stdClass $schema, Context $context)
    {
        $cacheKey = gettype($instance).spl_object_hash($schema);
        $constraints = & $this->constraintsCache[$cacheKey];

        if ($constraints === null) {
            $version = $this->getVersion($schema);
            $instanceType = Types::getPrimitiveTypeOf($instance);
            $constraints = $this->registry->getConstraintsForType($version, $instanceType);
            $constraints = $this->filterConstraintsForSchema($constraints, $schema);
        }

        foreach ($constraints as $constraint) {
            $constraint->apply($instance, $schema, $context, $this);
        }
    }