[caching] Store class/unit map in disk cache [5.3.0-B1]
This article will be about:
class map - allows to determine PHP file, that contains any class/interface/trait declaration
unit map - allows to determine PHP file, that has given unit config declaration
Currently both maps are stored either in database or memcache (only when memcache is installed). It works, but requires first to make a connection to database/memcache to get the current map version. Unfortunately this can end up in Fatal Error (e.g. [deployment] Trait usage results in fatal error during deploy [5.2.1]) because we use we're able to determine it's location.
Solution
each module will have following files:
{module_path}/install/cache/class_map.php (e.g. /modules/in-link/install/cache/class_map.php, /core/install/cache/class_map.php)
{module_path}/install/cache/unit_map.php
each file would start with following line to ensure that it's never checked by any static analysis tools (e.g. PHP_CodeSniffer, Phabricator):
// This file is @generated automaticallyintroduce "Generate class/unit maps" button in "System Tools", which only action would be to rebuild these map files
don't ever reset these map files by any automatic action, e.g. unit config cache rebuild or deploy
always include map files from all modules once we know what modules are installed
the class map files would go directly to kFactory and will power auto-loader
the unit map files would go directly to unit config reader and power the "getUnitConfigOption" and similar stuff
The proposed change will eliminate the situation, where a new file was discovered in the middle of application initialization and it can be used only on next page load, because it's not in cache. E.g. no custom rewrite listener is able to handle page load that triggered cache rebuild.
The catch in above changes is fact, that:
modules are allowed to replace classes, defined in other modules
unit configs can have priority specified and will be processed after other unit configs were processed