From 39fbc1b01d61c7f0199dac07738e62a927deb601 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Wed, 3 Sep 2025 08:20:34 +0200 Subject: [PATCH] feat: Build cache for character listings --- config/services.yaml | 3 +++ src/Controller/KanjiController.php | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/config/services.yaml b/config/services.yaml index cc56322..62f9bd8 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -5,12 +5,15 @@ # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: app.charlist.basepath: '%kernel.project_dir%/data/lists' + app.var.basepath: '%kernel.project_dir%/var' services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + bind: + string $varBasepath: '%app.var.basepath%' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/Controller/KanjiController.php b/src/Controller/KanjiController.php index 0a596e5..817a4f5 100644 --- a/src/Controller/KanjiController.php +++ b/src/Controller/KanjiController.php @@ -9,6 +9,7 @@ use App\Utils\Number; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\VarExporter\VarExporter; #[Route('/kanji', name: 'app_kanji_')] class KanjiController extends AbstractController @@ -16,6 +17,7 @@ class KanjiController extends AbstractController function __construct( private AnkiService $anki, private CharListService $charList, + private string $varBasepath, ) {} public static function tmpl(string $path): string @@ -26,6 +28,10 @@ class KanjiController extends AbstractController /** @return array> */ private function getCharInfo(): array { + $cacheFile = "$this->varBasepath/charlist.php"; + + if (file_exists($cacheFile)) return require $cacheFile; + $ret = []; $lists = [ @@ -59,6 +65,8 @@ class KanjiController extends AbstractController } } + file_put_contents($cacheFile, '