| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace RadiusTheme\SB\Modules; |
| 4 | - | |
| 5 | 4 | defined( 'ABSPATH' ) || exit(); |
| 6 | 5 | |
| 7 | 6 | use RadiusTheme\SB\Models\ModuleList; |
| 8 | 7 | |
| @@ -13,9 +12,9 @@ | ||
| 13 | 12 | use SingletonTrait; |
| 14 | 13 | |
| 15 | 14 | private $module_list; |
| 16 | 15 | |
| 17 | - private $module_instances = []; | |
| 16 | + private $module_instances = array(); | |
| 18 | 17 | private function __construct() { |
| 19 | 18 | add_action( 'init', [ $this, 'load_modules' ], 15 ); |
| 20 | 19 | } |
| 21 | 20 | |
| @@ -44,9 +43,21 @@ | ||
| 44 | 43 | if ( ! class_exists( $module['base_class'] ) ) { |
| 45 | 44 | continue; |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | - $module['base_class']::instance(); | |
| 47 | + // Check if the instance is already in the cache | |
| 48 | + $cached_instance = wp_cache_get( $module['base_class'], 'module_instances' ); | |
| 49 | + if ( false === $cached_instance ) { | |
| 50 | + // Create an instance and store it in the cache | |
| 51 | + $this->module_instances[ $module['base_class'] ] = $module['base_class']::instance(); | |
| 52 | + wp_cache_set( $module['base_class'], $this->module_instances[ $module['base_class'] ], 'module_instances' ); | |
| 53 | + } else { | |
| 54 | + // Use the cached instance | |
| 55 | + $this->module_instances[ $module['base_class'] ] = $cached_instance; | |
| 56 | + } | |
| 49 | 57 | |
| 50 | 58 | } |
| 59 | + | |
| 51 | 60 | } |
| 52 | -} | |
| 61 | + | |
| 62 | + | |
| 63 | +} | |