Skip to content

Commit f34968e

Browse files
committed
[Cache] Cache the parsed entrypoints.json
1 parent 95fdf56 commit f34968e

23 files changed

Lines changed: 1110 additions & 18 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ node_modules/
2323

2424
# PHP-CS-Fixer
2525
/.php-cs-fixer.cache
26+
27+
# Symfony config-builder reference, regenerated by the test kernel's cache warmer.
28+
/config/reference.php

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getRuleCustomisers(): array
5959
$relativePathname = $file->getRelativePathname();
6060

6161
if (
62-
str_contains($relativePathname, '/tests/') // don't touch test files, as massive change with little benefit - as outside of public contract anyway
62+
str_contains($relativePathname, 'tests/') // don't touch test files, as massive change with little benefit - as outside of public contract anyway
6363
|| str_contains($relativePathname, '/Test/') // public namespace not following the rule, do not mistake it with `/Tests/`
6464
) {
6565
return false;

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"phpunit/phpunit": "^13.2",
2525
"phpstan/phpstan": "^2.2",
2626
"friendsofphp/php-cs-fixer": "^3.95",
27-
"symfony/web-link": "^7.4|^8.0"
27+
"symfony/web-link": "^7.4|^8.0",
28+
"symfony/cache": "^7.4|^8.0",
29+
"symfony/var-exporter": "^7.4|^8.0"
2830
},
2931
"autoload": {
3032
"psr-4": { "Symfony\\Reprise\\": "src/" }

config/cache.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
15+
use Symfony\Reprise\CacheWarmer\EntrypointsCacheWarmer;
16+
17+
return static function (ContainerConfigurator $container): void {
18+
$services = $container->services();
19+
20+
$services->set('cache.reprise')
21+
->parent('cache.system')
22+
->tag('cache.pool')
23+
;
24+
25+
$services->set('reprise.cache', PhpArrayAdapter::class)
26+
->args([
27+
'%kernel.build_dir%/reprise.cache.php',
28+
service('cache.reprise'),
29+
])
30+
;
31+
32+
$services->set('reprise.entrypoints_cache_warmer', EntrypointsCacheWarmer::class)
33+
->args([
34+
param('reprise.entrypoints_path'),
35+
'reprise.entrypoints',
36+
service('reprise.cache'),
37+
])
38+
->tag('kernel.cache_warmer')
39+
;
40+
};

doc/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ Reprise exposes a few optional settings under its own configuration, all shown h
154154
# Throw when entrypoints.json or a requested entry is missing, instead of rendering nothing.
155155
strict_mode: true
156156
157+
# Cache the parsed entrypoints.json in a compiled PHP file, warmed at cache:warmup (needs symfony/cache).
158+
cache: false
159+
157160
# A framework.assets package name used to resolve entry URLs. null uses the default package.
158161
asset_package: null
159162
@@ -171,6 +174,9 @@ Reprise exposes a few optional settings under its own configuration, all shown h
171174
own ``outputPath``.
172175
- ``strict_mode``: when ``true`` (the default), throws a clear exception on a missing file or an unknown entry; when
173176
``false``, renders nothing instead.
177+
- ``cache``: when ``true``, parse ``entrypoints.json`` once at ``cache:warmup`` and read it from a compiled PHP file
178+
at runtime instead of decoding the JSON on every request. Enable it in production and run ``cache:clear`` after
179+
rebuilding your assets; it needs ``symfony/cache`` (``composer require symfony/cache``).
174180
- ``asset_package``: resolve entry URLs through a specific ``framework.assets`` package instead of the default one.
175181
You only need this if your default package applies a version strategy, which would re-hash files Reprise already
176182
content-hashed and break the URLs. Point it at a package with ``version: false`` (see below).

0 commit comments

Comments
 (0)