は、キャッシュを使用し、バンドルの開発に大きく依存しています。 symfonyの標準バージョンに付属するdoctrineでさえ、キャッシュクリアコマンドが統合されています。このようなリスナー登録
<?php
namespace DefaultBundle\Event\Listener;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Process\Process;
class CacheClearListener implements CacheClearerInterface
{
private $environment;
/**
* @return array
*/
private static function getCommands()
{
return array(
'php ./app/console doctrine:cache:clear-metadata --no-debug --flush',
'php ./app/console doctrine:cache:clear-query --no-debug --flush',
'php ./app/console doctrine:cache:clear-result --no-debug --flush'
);
}
public function clear($cacheDir)
{
$output = new ConsoleOutput();
$output->writeln('');
$output->writeln('<info>Clearing Doctrine cache</info>');
foreach (self::getCommands() as $command) {
$command .= ' --env='.$this->environment;
$success = $this->executeCommand($command, $output);
if (!$success) {
$output->writeln(sprintf('<info>An error occurs when running: %s!</info>', $command));
exit(1);
}
}
}
/**
* @param string $command
* @param ConsoleOutput $output
*
* @return bool
*/
private function executeCommand($command, ConsoleOutput $output)
{
$p = new Process($command);
$p->setTimeout(null);
$p->run(
function ($type, $data) use ($output) {
$output->write($data, false, OutputInterface::OUTPUT_RAW);
}
);
if (!$p->isSuccessful()) {
return false;
}
$output->writeln('');
return true;
}
/**
* @param Kernel $kernel
*/
public function setKernel(Kernel $kernel)
{
$this->environment = $kernel->getEnvironment();
}
}
:
<service id="cache_clear_listener" class="DefaultBundle\Event\Listener\CacheClearListener">
<call method="setKernel">
<argument type="service" id="kernel"/>
</call>
<tag name="kernel.cache_clearer" priority="254" />
</service>
をそして、それがすべてであるしかし、あなたにできることは、あなたがこのようにしたいすべてのキャッシュをクリアコマンドを実行し、リスナーにデフォルトのsymfonyコマンドを拡張しています。これで、getCommands()メソッドに新しいcache clearコマンドを追加し続けるだけです。これは、あなたのリスナーは、あなたがPHPアプリ/コンソールを実行するたびに設定された後、それらに
の単語「キャッシュ」を含むすべての利用可能なコマンドを参照してください
php app/console | grep cache
のようなものを実行できるコマンドを見つけるためにcache:クリアすると、リスナーのgetCommands()メソッドにリストされているすべてのコマンドがトリガーされます。このことができます
希望、 アレクサンドル
のrm -rするvar /キャッシュは、トリックを行います。すべてがキャッシュディレクトリの下にあります。しかし、私はあなたがドキュメントを誤解しているかもしれないと思います。はい、doctrineはキャッシュのためのコマンドを提供していますが、symfonyのキャッシュはクリアされています。それを試してみてください。 – Cerad
redisを使用する場合など、すべてのキャッシュがディスクに書き込まれるわけではありません。 – Bruno