From a5d6e40c7dad58f69ce39c501561e3662e42a433 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 10 Apr 2020 11:15:26 +0200 Subject: [PATCH] Document that cache warmers now must return an array of files to preload --- reference/dic_tags.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index d07716d296b..c65e0448c80 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -468,6 +468,7 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i // src/Cache/MyCustomWarmer.php namespace App\Cache; + use App\Foo\Bar; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; class MyCustomWarmer implements CacheWarmerInterface @@ -475,6 +476,17 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i public function warmUp($cacheDirectory) { // ... do some sort of operations to "warm" your cache + + $filesAndClassesToPreload = []; + $filesAndClassesToPreload[] = Bar::class; + + foreach (scandir($someCacheDir) as $file) { + if (!is_dir($file = $someCacheDir.'/'.$file)) { + $filesAndClassesToPreload[] = $file; + } + } + + return $filesAndClassesToPreload; } public function isOptional() @@ -483,6 +495,16 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i } } +The ``warmUp()`` method must return an array with the files and classes to +preload. Files must be absolute paths and classes must be fully-qualified class +names. The only restriction is that files must be stored in the cache directory. +If you don't need to preload anything, return an empty array + +.. deprecated:: 5.1 + + Not returning an array from the ``warmUp()`` method with the files to + preload is deprecated since Symfony 5.1. + The ``isOptional()`` method should return true if it's possible to use the application without calling this cache warmer. In Symfony, optional warmers are always executed by default (you can change this by using the