Creating a dedicated translations cache driver

parent fefcdba4
......@@ -13,6 +13,7 @@ DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=array
TRANSLATIONS_CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
......
......@@ -89,10 +89,6 @@ class TranslationServiceProvider extends ServiceProvider
$this->app->bind(TranslationRepository::class, function () {
$repository = new EloquentTranslationRepository(new Translation());
if (! config('app.cache')) {
return $repository;
}
return new CacheTranslationDecorator($repository);
});
......
......@@ -26,8 +26,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
$locale = $locale ?: app()->getLocale();
return $this->cache
->tags([$this->entityName, 'global'])
return app('cache')->driver('translations')
->rememberForever("{$this->entityName}.findByKeyAndLocale.{$cleanKey}.{$locale}",
function () use ($key, $locale) {
return $this->repository->findByKeyAndLocale($key, $locale);
......@@ -37,8 +36,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
public function allFormatted()
{
return $this->cache
->tags([$this->entityName, 'global'])
return app('cache')->driver('translations')
->rememberForever("{$this->locale}.{$this->entityName}.allFormatted",
function () {
return $this->repository->allFormatted();
......@@ -48,7 +46,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
public function saveTranslationForLocaleAndKey($locale, $key, $value)
{
$this->cache->tags($this->entityName)->flush();
app('cache')->driver('translations')->flush();
return $this->repository->saveTranslationForLocaleAndKey($locale, $key, $value);
}
......@@ -57,8 +55,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
{
$cleanKey = $this->cleanKey($key);
return $this->cache
->tags([$this->entityName, 'global'])
return app('cache')->driver('translations')
->rememberForever("{$this->locale}.{$this->entityName}.findTranslationByKey.{$cleanKey}",
function () use ($key) {
return $this->repository->findTranslationByKey($key);
......@@ -74,7 +71,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
*/
public function updateFromImport($key, array $data)
{
$this->cache->tags($this->entityName)->flush();
app('cache')->driver('translations')->flush();
return $this->repository->updateFromImport($key, $data);
}
......@@ -87,7 +84,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
*/
public function updateTranslationToValue(TranslationTranslation $translationTranslation, $value)
{
$this->cache->tags($this->entityName)->flush();
app('cache')->driver('translations')->flush();
return $this->repository->updateTranslationToValue($translationTranslation, $value);
}
......@@ -104,8 +101,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
public function getTranslationsForGroupAndNamespace($locale, $group, $namespace)
{
return $this->cache
->tags([$this->entityName, 'global'])
return app('cache')->driver('translations')
->rememberForever("{$this->entityName}.findByKeyAndLocale.{$locale}.{$group}.[$namespace]",
function () use ($locale, $group, $namespace) {
return $this->repository->getTranslationsForGroupAndNamespace($locale, $group, $namespace);
......
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
added:
- New cache driver specifically for translations, making translations always cached
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
......
......@@ -71,6 +71,10 @@ return [
'connection' => 'default',
],
'translations' => [
'driver' => env('TRANSLATIONS_CACHE_DRIVER', 'file'),
'path' => storage_path('framework/cache'),
],
],
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment