@@ -468,13 +468,25 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i
468
468
// src/Cache/MyCustomWarmer.php
469
469
namespace App\Cache;
470
470
471
+ use App\Foo\Bar;
471
472
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
472
473
473
474
class MyCustomWarmer implements CacheWarmerInterface
474
475
{
475
476
public function warmUp($cacheDirectory)
476
477
{
477
478
// ... 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;
478
490
}
479
491
480
492
public function isOptional()
@@ -483,6 +495,16 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i
483
495
}
484
496
}
485
497
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
+
486
508
The ``isOptional() `` method should return true if it's possible to use the
487
509
application without calling this cache warmer. In Symfony, optional warmers
488
510
are always executed by default (you can change this by using the
0 commit comments