存储库中的静态:良好的做法?

In my Repository, I have a function " count_locations($building) ".

But this function is called several times in the page : in the controller, in two services and in menu (KnpMenuBundle).

What is the best practice for to avoid not repeat the request ? Create in repository static variable for result ?

Since instantiating a repository is done automatically, I would suggest have a class method that calls a static method/variable to return the results. Thereby you do not need to have it run multiple times and also not worry about getting the Entity/Object manager and the connection by not instantiating the repository through Doctrine.