samedi 11 juillet 2015

Caching Dependencies in PHP

I have a small system that is built on top of an IoC container. That IoC container has the ability to automatically resolve dependencies of a requested class by using reflections (ReflectionClass, ReflectionMethod, ...) and inject those dependencies into the constructor of the class.

The problem is that i have read many posts saying that reflection is a very slow approach and using it every run is a bad practice.

Therefore, i want to avoid using reflection every run and my idea is to cache the dependencies or a requested class.

I will cache both the dependencies of a class and an hashed version of the code of the class, that way i will know when to re-evaluate the dependencies of class (when the hash of the class code doesn't match the hash that is cached, in other words, the code was modified since the last evaluation of the dependencies).

Is this a good approach or should i stay with the reflection every run approach? My main concerns are of whether this approach will help to optimize the system performances or will it just slow it down?

Thank, Arik





Aucun commentaire:

Enregistrer un commentaire