oops / morozko
Cache warmup library for Nette Framework.
Installs: 10 094
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >= 7.1.0
- nette/di: ^2.4.10
- nette/finder: ^2.4
- ocramius/package-versions: ^1.1
- psr/log: ^1.0
- symfony/console: ^3.3||^4.0
Requires (Dev)
- kdyby/console: ^2.7.0
- mockery/mockery: ^1.0.0
- nette/bootstrap: ^2.4.0
- nette/tester: ^2.0.0
This package is auto-updated.
Last update: 2022-02-01 13:11:37 UTC
README
⚠️ THIS PACKAGE IS NO LONGER MAINTAINED. You can use the AdvancedCache module from contributte/console-extra instead.
Are you warm yet, my little application?
Morozko is a utility for cache warmup in a Nette Framework application.
Installation and requirements
$ composer require oops/morozko
Oops/Morozko requires PHP >= 7.1.
Oops/Morozko provides a Symfony/Console command, thus, you must also install and configure a Symfony/Console integration package such as Kdyby/Console or contributte/console.
Usage
Register the extension in your config file. Don't forget to register a Symfony/Console integration as well:
extensions: morozko: Oops\Morozko\DI\MorozkoExtension console: Kdyby\Console\DI\ConsoleExtension
Then you can directly run the oops:morozko:warmup
command, or add it to your deploy process.
Default cache warmers
By default, the oops:morozko:warmup
command executes one default cache warmer: the NetteConfiguratorCacheWarmer
, which compiles the DI container.
To be able to do so, it needs to know how your DI container is configured - you need to provide it with an implementation of ConfiguratorFactoryInterface
whose create()
method should return the same Configurator
as in your application's bootstrap.php
. Actually, it might be wise to use the implementation in bootstrap.php
to prevent code duplication.
<?php namespace My\Application; use Nette\Configurator; use Oops\Morozko\CacheWarmers\NetteConfiguratorCacheWarmer\ConfiguratorFactoryInterface; final class ConfiguratorFactory implements ConfiguratorFactoryInterface { public function create(): Configurator { $configurator = new Configurator(); // ... configure application ... return $configurator; } }
morozko: configuratorFactory: My\Application\ConfiguratorFactory
Be aware that in CLI the %wwwDir%
and %appDir%
parameters might not actually point to the document root. For example, if you run console commands via bin/console.php
, it will likely point to the bin
directory.
If that is your case, you need to set the parameters to the correct values in your configurator factory, otherwise the generated DI container won't match the one actually used in production:
<?php $configurator = new Nette\Configurator(); $configurator->addParameters([ 'appDir' => __DIR__, 'wwwDir' => __DIR__ . '/../www', ]); // ...
Additional cache warmers
There are currently these official additions to the Morozko's DI container cache warmer:
oops/morozko-latte-bridge
pre-compiles all Latte templates found within a configured directory.oops/morozko-doctrine-bridge
warms up Doctrine metadata cache and generates entity proxies.
Custom cache warmers
You can also create your own cache warmers. Simply create a class implementing the Oops\Morozko\CacheWarmer
interface and register it as a service into the DI container.
Third-party cache warmers
If you have a cache warmer that you'd like to share with others, feel free to add it to this section via a pull request.