I have a project that uses Symfony framework. For optimisation purposes I have narrowed down 6 common variables which are being used constanly during a request. Some of this variables are inside database.
Now, it is bad practise to go back to database again and again 5 times, getting same values. So, I thought of storing those variable value into class level variable.
Is it a good practise?
class MyController extends Controller
{
/*Class level variables to eliminate repetitive object creation.*/
protected $doctrine;
What you can do is to create another
extendsbetween your controller and base controller of symfony. Like this:and ApplicationController could have methods like this:
This example shows that instance of logged User is “cached”; that is what you need right? You could use the same idea for other things you need often.