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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user