Creating a dedicated translations cache driver

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