Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
d419ff0c
Unverified
Commit
d419ff0c
authored
Jul 18, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creating a dedicated translations cache driver
parent
fefcdba4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
15 deletions
+14
-15
.env.example
.env.example
+1
-0
TranslationServiceProvider.php
Modules/Translation/Providers/TranslationServiceProvider.php
+0
-4
CacheTranslationDecorator.php
...nslation/Repositories/Cache/CacheTranslationDecorator.php
+7
-11
changelog.yml
Modules/Translation/changelog.yml
+2
-0
cache.php
config/cache.php
+4
-0
No files found.
.env.example
View file @
d419ff0c
...
@@ -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
...
...
Modules/Translation/Providers/TranslationServiceProvider.php
View file @
d419ff0c
...
@@ -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
);
});
});
...
...
Modules/Translation/Repositories/Cache/CacheTranslationDecorator.php
View file @
d419ff0c
...
@@ -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
);
...
...
Modules/Translation/changelog.yml
View file @
d419ff0c
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
...
...
config/cache.php
View file @
d419ff0c
...
@@ -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'
),
],
],
],
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment