[caching] Store class/unit map in disk cache [5.3.0-B1]

[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

  1. each module will have following files:

    1. {module_path}/install/cache/class_map.php (e.g. /modules/in-link/install/cache/class_map.php, /core/install/cache/class_map.php)

    2. {module_path}/install/cache/unit_map.php

  2. 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 automatically

  3. introduce "Generate class/unit maps" button in "System Tools", which only action would be to rebuild these map files

  4. don't ever reset these map files by any automatic action, e.g. unit config cache rebuild or deploy

  5. always include map files from all modules once we know what modules are installed

  6. the class map files would go directly to kFactory and will power auto-loader

  7. 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.

Related Discussions

Related Tasks

https://in-portal.atlassian.net/browse/INP-1422

Comments