1
0
mirror of https://github.com/flarum/core.git synced 2025-07-26 03:01:22 +02:00

Performance: Actually make use of the translator cache

We had added a `storage/locale` directory to our skeleton, but we had
forgotten to hook it up with the translator. Enabling caching saves
parsing that locale YAML files on every pageload which should be good
for performance.

The locale cache will be cleared whenever an extension that uses the
`Locales` or `LanguagePack` extenders is enabled/disabled. If debug
mode is ON, then the caching mechanism will automatically check if any
of the loaded YAML files are dirty and update accordingly.
This commit is contained in:
Toby Zerner
2018-12-07 09:38:08 +10:30
parent 6b6fce878a
commit 13ce2d1e3d
4 changed files with 60 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ use Illuminate\Contracts\Container\Container;
use InvalidArgumentException;
use RuntimeException;
class LanguagePack implements ExtenderInterface
class LanguagePack implements ExtenderInterface, LifecycleInterface
{
public function extend(Container $container, Extension $extension = null)
{
@@ -63,4 +63,14 @@ class LanguagePack implements ExtenderInterface
}
}
}
public function onEnable(Container $container, Extension $extension)
{
$container->make('flarum.locales')->clearCache();
}
public function onDisable(Container $container, Extension $extension)
{
$container->make('flarum.locales')->clearCache();
}
}

View File

@@ -16,7 +16,7 @@ use Flarum\Extension\Extension;
use Flarum\Locale\LocaleManager;
use Illuminate\Contracts\Container\Container;
class Locales implements ExtenderInterface
class Locales implements ExtenderInterface, LifecycleInterface
{
protected $directory;
@@ -46,4 +46,14 @@ class Locales implements ExtenderInterface
);
}
}
public function onEnable(Container $container, Extension $extension)
{
$container->make('flarum.locales')->clearCache();
}
public function onDisable(Container $container, Extension $extension)
{
$container->make('flarum.locales')->clearCache();
}
}