-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use system cache for ComponentProperties + add CacheWarmer
- Loading branch information
Showing
6 changed files
with
140 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\TwigComponent\DependencyInjection\Loader\Configurator; | ||
|
||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $container): void { | ||
$container->services() | ||
->set('cache.ux.twig_component') | ||
->parent('cache.system') | ||
->private() | ||
->tag('cache.pool') | ||
; | ||
}; |
55 changes: 55 additions & 0 deletions
55
src/TwigComponent/src/CacheWarmer/TwigComponentCacheWarmer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\TwigComponent\CacheWarmer; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; | ||
use Symfony\Contracts\Service\ServiceSubscriberInterface; | ||
use Symfony\UX\TwigComponent\ComponentProperties; | ||
|
||
/** | ||
* Warm the TwigComponent metadata caches. | ||
* | ||
* @author Simon André <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
final class TwigComponentCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface | ||
{ | ||
/** | ||
* As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected. | ||
*/ | ||
public function __construct( | ||
private readonly ContainerInterface $container, | ||
) { | ||
} | ||
|
||
public static function getSubscribedServices(): array | ||
{ | ||
return [ | ||
'ux.twig_component.component_properties' => ComponentProperties::class, | ||
]; | ||
} | ||
|
||
public function warmUp(string $cacheDir, ?string $buildDir = null): array | ||
{ | ||
$properties = $this->container->get('ux.twig_component.component_properties'); | ||
$properties->warmup(); | ||
|
||
return []; | ||
} | ||
|
||
public function isOptional(): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters