Skip to content

Commit 3dea179

Browse files
committed
Merge branch '5.1'
* 5.1: Document that cache warmers now must return an array of files to preload
2 parents 82e1a86 + 635370d commit 3dea179

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

reference/dic_tags.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,25 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i
468468
// src/Cache/MyCustomWarmer.php
469469
namespace App\Cache;
470470

471+
use App\Foo\Bar;
471472
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
472473

473474
class MyCustomWarmer implements CacheWarmerInterface
474475
{
475476
public function warmUp($cacheDirectory)
476477
{
477478
// ... do some sort of operations to "warm" your cache
479+
480+
$filesAndClassesToPreload = [];
481+
$filesAndClassesToPreload[] = Bar::class;
482+
483+
foreach (scandir($someCacheDir) as $file) {
484+
if (!is_dir($file = $someCacheDir.'/'.$file)) {
485+
$filesAndClassesToPreload[] = $file;
486+
}
487+
}
488+
489+
return $filesAndClassesToPreload;
478490
}
479491

480492
public function isOptional()
@@ -483,6 +495,16 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i
483495
}
484496
}
485497

498+
The ``warmUp()`` method must return an array with the files and classes to
499+
preload. Files must be absolute paths and classes must be fully-qualified class
500+
names. The only restriction is that files must be stored in the cache directory.
501+
If you don't need to preload anything, return an empty array
502+
503+
.. deprecated:: 5.1
504+
505+
Not returning an array from the ``warmUp()`` method with the files to
506+
preload is deprecated since Symfony 5.1.
507+
486508
The ``isOptional()`` method should return true if it's possible to use the
487509
application without calling this cache warmer. In Symfony, optional warmers
488510
are always executed by default (you can change this by using the

0 commit comments

Comments
 (0)