Disable @Groups annotations caching in Symfony 5

I am using Symfony 5 and I have a weird issue with @Groups annotations.

I have my Entity with a @Groups named public:article

class Article
{
    /**
     * @ORMId
     * @ORMGeneratedValue
     * @ORMColumn(type="integer")
     * @Groups({"public:article"})
     */
    private $id;

    /**
     * @ORMColumn(type="text", nullable=true)
     * @Groups({"public:article"})
     */
    private $title;
     ...
}

In my controller, I use the method findAll of my ArticleRepository :

/**
     * @Route(name="api_allArticles", path="/api/article", methods="GET")
     * @return JsonResponse
     */
    public function getAllArticles(): JsonResponse
    {
        $items = $this->articleRepository->findAll();
        return $this->json($items, 200,[],["groups" => "public:article"]);
    }

When I call the route, I get an array of articles [{id: 1, title: 'Article title 1}]

If I remove (or add, or modify) the @Groups annotation, for instance on the title property, the response is exactly the same, like it doesn’t take into account the change.
But if I call php bin/console cache:clear, then afterwards, the api call returns correctly an array of articles without the title property.

I am in a development environment (APP_ENV=dev in .env file) and it is very annoying to debug my app and to run this cache:clear command everytime I make a change.

How can I disable this caching ?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *