The container_builder allows for the cache directory to be overridden by $SERVER['PHPBB____core__cache_dir']. This is because get_core_parameters wants it values to be extended and overwritten by get_env_parameters, which will read PHPBB__ keys from $_SERVER.
So we can set a custom cache directory via:
$_SERVER['PHPBB____core__cache_dir'] = '/some/path';
When the container is built (via get_container) the application will use our supplied cache directory, but, the container_builder will create the autoloader and container cache files in phpbb_root_path/cache/<env>. This seems like inconsistent behavior. It would be more consistent if the container_builder would also use the overwritten cache_dir.
I've attached a test file which demonstrates the buggy behavior, and contains a (skipped) test for the desired behavior.
The Pull Request for this fix can be found here: https://github.com/phpbb/phpbb/pull/5707