Cache

The point of the Autoloader cache is to record the path to the script containing the class when it is first discovered, so that you don't have to call loaders next time. This saves hundreds (if not thousands) of calls and all the associated overhead. Thus, the cache is a key component of the autoloader.

And the autoloader cache is modular. You can swap its backend, develop your own. The PHP Jet one backend is part of it, and it is of course used as the default.

If you need to make a custom backend, just create a class that implements the interface.

Initialization

The cache is initialized in the script ~/application/Init/Cache/Autoloader.php, specifically as follows: require_once SysConf_Path::getLibrary() . 'Jet/Autoloader/Cache/Backend/Files.php'Autoloader_Cache::init( new Autoloader_Cache_Backend_Files() ); It is important to use SysConf_Path and the classic require!

Configuration

Within the SysConf_Jet configuration, there are isCacheAutoloaderEnabled(): bool and setCacheAutoloaderEnabled( bool $cache_autoloader_enabled ): void methods to enable and disable the cache autoloader.

In practice, I use this so that the cache is inactive in the development environment and active in the production environment, and if the situation requires it, the cache needs to be devalidated (simply delete the files) when a new version is deployed to production.

The configuration is by default in the script ~/application/config/Jet.php and specifically here:

//.....................
if( SysConf_Jet::isDevelMode() ) {
    
//Dev configuration
        //.....................
    
SysConf_Jet::setCacheAutoloaderEnabledfalse );
        
//.....................
} else {
    
//Production configuration
        //.....................
    
SysConf_Jet::setCacheAutoloaderEnabledtrue );
        
//.....................
}

Use

The Jet\Autoloader_Cache container is for the actual use of the cache. Thus, the backend is not used directly.

In the application space, there is no need to care about the autoloader cache. The system handles everything internally.

Previous chapter
Loader
Next chapter
Jet\Autoloader_Cache