Getting error “Cannot redeclare class __TwigTemplate”

Im trying to write twig loader that would load templates depending on the city and the partner who announced me in the app. And im getting error when i run my php app. Сlass is loaded correctly into the cache the first time, but then for some reason I try to create another class

Compile Error: Cannot redeclare class __TwigTemplate_91fb729aa360daba88c8f80ea708ed40 (previously declared in /var/www/var/cache/dev/twig/f1/f1f0c5a29775ffb735cb305c2a82df1f.php:16)

Here is my code:


readonly class PartnerTemplateLoader implements LoaderInterface
{
    const string DEFAULT_TEMPLATES_PATH = "Default";

    const string VIEWS_DIR = 'Resources/views';

    public function __construct(
        private KernelInterface $kernel,
        private Partner $partner,
        private City $city,
        private string $defaultTemplatesPath = self::DEFAULT_TEMPLATES_PATH
    ) {}

    public function getSourceContext($name): Source
    {
        $template = $this->loadTemplate($name);
        return new Source(
            file_get_contents(
                $this->kernel->locateResource($template->absoluteName)
            ),
            $template->name,
            $template->absoluteName
        );
    }

    public function getCacheKey($name): string
    {
        $template = $this->loadTemplate($name);
        return $template->name;
    }

    public function isFresh($name, $time): bool
    {
        $template = $this->loadTemplate($name);

        return filemtime($this->kernel->locateResource($template->absoluteName)) <= $time;
    }

    public function exists($name): bool
    {
       return $this->findTemplate($name);
    }

    private function loadTemplate(string $name): Template
    {
        $name = str_replace(
            ":/",
            ":",
            preg_replace("#/{2,}#", "/", strtr($name, "\", "/"))
        );

        if (str_contains($name, "..")) {
            throw new RuntimeException(
                sprintf('Template name "%s" contains invalid characters.', $name)
            );
        }

        preg_match('/^([^:]*)/([^:]*)/(.+).([^.]+).([^.]+)$/', $name, $matches);

        try {
            if (count($matches) === 0) {
                return new Template($name);
            }
        } catch (Throwable $e) {}

        try {
            $absoluteName = $this->prepareAbsolutePartnerName($matches, $this->city->getSlug());
            $name = $this->preparePartnerName($matches, $this->city->getSlug());
            if ($this->kernel->locateResource($absoluteName)) {
                return new Template($name, $absoluteName);
            }
        } catch (Throwable $e) {}

        try {
            $absoluteName = $this->prepareAbsolutePartnerName($matches, $this->defaultTemplatesPath);
            $name = $this->preparePartnerName($matches, $this->defaultTemplatesPath);
            if ($this->kernel->locateResource($absoluteName)) {
                return new Template($name, $absoluteName);
            }
        } catch (Throwable $exception) {}

        $absoluteName = $this->prepareAbsoluteDefaultName($matches);
        $name = $this->prepareDefaultName($matches);
        if ($this->kernel->locateResource($this->prepareAbsoluteDefaultName($matches))) {
            return new Template($name, $absoluteName);
        }

        throw new RuntimeException('Cannot load template!');
    }

    private function findTemplate(string $name): bool
    {
        $found = false;
        $name = str_replace(
            ":/",
            ":",
            preg_replace("#/{2,}#", "/", strtr($name, "\", "/"))
        );

        if (str_contains($name, "..")) {
            throw new RuntimeException(
                sprintf('Template name "%s" contains invalid characters.', $name)
            );
        }

        preg_match('/^([^:]*)/([^:]*)/(.+).([^.]+).([^.]+)$/', $name, $matches);

        try {
            if (count($matches) === 0 && $this->kernel->locateResource($name)) {
                $found = true;
            }
        } catch (Throwable $e) {}

        try {
            if ($this->kernel->locateResource($this->prepareAbsolutePartnerName($matches, $this->city->getSlug()))) {
                $found = true;
            }
        } catch (Throwable $e) {}

        try {
            if ($this->kernel->locateResource($this->prepareAbsolutePartnerName($matches, $this->defaultTemplatesPath))) {
                $found = true;
            }
        } catch (Throwable $e) {}

        try {
            if ($this->kernel->locateResource($this->prepareAbsoluteDefaultName($matches))) {
                $found = true;
            }
        } catch (Throwable $e) {}

        return $found;
    }

    private function prepareDefaultName(array $matches): string
    {
        return "{$matches[1]}/{$this->defaultTemplatesPath}/{$matches[2]}/{$matches[3]}.{$matches[4]}.{$matches[5]}";
    }

    private function preparePartnerName(array $matches, string $city): string
    {
        return "{$matches[1]}/{$this->partner->getTemplatesPath()}/{$city}/{$matches[2]}/{$matches[3]}.{$matches[4]}.{$matches[5]}";
    }

    private function prepareAbsoluteDefaultName(array $matches): string
    {
        $absoluteBundlePath =  $matches[1] . "/" . self::VIEWS_DIR;
        return "{$absoluteBundlePath}/{$this->defaultTemplatesPath}/{$matches[2]}/{$matches[3]}.{$matches[4]}.{$matches[5]}";
    }

    private function prepareAbsolutePartnerName(array $matches, string $city): string
    {
        $absoluteBundlePath =  $matches[1] . "/" . self::VIEWS_DIR;
        return "{$absoluteBundlePath}/{$this->partner->getTemplatesPath()}/{$city}/{$matches[2]}/{$matches[3]}.{$matches[4]}.{$matches[5]}";
    }
}

I tried to clear and warmup my cache and change template names