Skip to content

Commit

Permalink
moved the delete cache dir logic to the boot method instead of the in…
Browse files Browse the repository at this point in the history
…itializeContainer
  • Loading branch information
Niv authored and mmoreram committed Feb 15, 2021
1 parent 3e7ccc7 commit 8f6891d
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions AsyncKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public function boot()
$this->uid = $this->generateUID();
}

$fs = new Filesystem();
// AsyncKernel loads the container only once when it loads. Storing it in the filesystem is not for cache purposes
// but more for using the same loading process as Kernel class use.
// Hence, everytime before AsyncKernel initiates the container it deletes the cache dir,
// to make sure it is building the updated kernel
$cachePath = $this->getCacheDir();
if ($fs->exists($cachePath)) {
$fs->remove($cachePath);
}

parent::boot();
}

Expand Down Expand Up @@ -177,26 +187,4 @@ public function processTimer(ContainerBuilder $container)

$container->setDefinition(PeriodicTimer::class, $periodicTimer);
}

/**
* Initializes the service container.
*
* The cached version of the service container is used when fresh, otherwise the
* container is built.
*/
protected function initializeContainer()
{
$fs = new Filesystem();
// AsyncKernel loads the container only once when it loads. Storing it in the filesystem is not for cache purposes
// but more for using the same loading process as Kernel class use.
// Hence, everytime before AsyncKernel initiates the container it deletes the cache dir,
// to make sure it is building the updated kernel
$cachePath = $this->getCacheDir();
if ($fs->exists($cachePath)) {
$fs->remove($cachePath);
}

// initialize the kernel
parent::initializeContainer();
}
}

0 comments on commit 8f6891d

Please sign in to comment.