From 46c06d4966a81e0307487141ddfc993ee9705745 Mon Sep 17 00:00:00 2001 From: Bart Jaskulski <bjaskulski@protonmail.com> Date: Mon, 8 Jul 2024 09:06:50 +0200 Subject: [PATCH] refactor: use cache, only if previously built Signed-off-by: Bart Jaskulski <bjaskulski@protonmail.com> --- src/Kernel.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Kernel.php b/src/Kernel.php index ccd157f..931db22 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -86,12 +86,14 @@ final class Kernel { private function initialize_container( Plugin $plugin ): Container { $original_builder = new DiBuilder(); - $original_builder->enableCompilation( - $this->get_cache_path(), - $this->get_container_name( $plugin ) - ); + // If there's a cache file, use it as we are in production environment. + // Otherwise, build the container from scratch and use live version, without compilation. if ( file_exists( $this->get_cache_path( $this->get_container_name( $plugin ) . '.php' ) ) ) { + $original_builder->enableCompilation( + $this->get_cache_path(), + $this->get_container_name( $plugin ) + ); return $original_builder->build(); } -- GitLab