Caching your ZF2 merged configuration | Rob Allen's DevNotes

:

Zend Framework 2's ModuleManager has the ability to cache the merged configuration information for your application. This is very useful as it allows you to separate out your configuration within the config/autoload directory into logical files without worrying about the performance implications of lots of files.

Enabling caching is simply a case of setting these configuration keys in config/application.config.php within the module_listener_options section:

This then creates the cache files data/cache/module-classmap-cache.php and data/cache/module-config-cache.php and you're done. If you need to regenerate the files, simply delete then.

During development this can be a pain to remember!

We can solve this by only caching when in production. The easiest way to do this is by setting an environment variable in your virtual host. For Apache, use SetEnv; you're on your own for any other web server.

The way I do this is to modify config/application.config.php like this:

I then create a separate configuration file for each environment. For production, I turn on caching:

config/application.config.production.php:

and for my local development, I add some development modules:

config/application.config.development.php:

This system allows me to have a faster production site and specific modules loaded when developing that make life easier.