Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SettingsBundle
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Symfony2
SettingsBundle
Commits
e7b98422
Commit
e7b98422
authored
4 years ago
by
Aleksandr Borodulin
Browse files
Options
Downloads
Patches
Plain Diff
Cache changes
parent
de10c732
No related branches found
Branches containing commit
Tags
v5.1.2
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Core/SettingsLoader.php
+12
-19
12 additions, 19 deletions
Core/SettingsLoader.php
with
12 additions
and
19 deletions
Core/SettingsLoader.php
+
12
−
19
View file @
e7b98422
...
...
@@ -15,26 +15,18 @@ use Symfony\Component\Cache\Adapter\FilesystemAdapter;
class
SettingsLoader
{
const
DEFAULT_LIFE_TIME
=
3600
;
/**
* @var Repository
*/
protected
$repository
;
/**
* @var Cache
*/
protected
$cacheProvider
;
protected
Repository
$repository
;
protected
FilesystemAdapter
$cacheProvider
;
/**
* Construct
*
* @param Repository
$repository
* @param Repository $repository
*/
public
function
__construct
(
Repository
$repository
)
{
$this
->
repository
=
$repository
;
$this
->
cacheProvider
=
new
FilesystemAdapter
();
$this
->
cacheProvider
=
new
FilesystemAdapter
(
'settings'
);
}
/**
...
...
@@ -44,9 +36,9 @@ class SettingsLoader
* @param mixed $default
* @return mixed
*/
public
function
get
(
$key
,
$default
=
null
)
public
function
get
(
string
$key
,
$default
=
null
)
{
return
$this
->
load
(
$key
,
$default
)
->
get
()
;
return
$this
->
load
(
$key
,
$default
);
}
/**
...
...
@@ -55,7 +47,7 @@ class SettingsLoader
* @param string $key
* @return bool
*/
public
function
remove
(
$key
)
public
function
remove
(
string
$key
):
bool
{
if
(
$this
->
cacheProvider
->
hasItem
(
$key
))
{
return
$this
->
cacheProvider
->
delete
(
$key
);
...
...
@@ -68,13 +60,13 @@ class SettingsLoader
* Load setting value
*
* @param string $key
* @param mixed $default
* @param mixed
$default
* @return mixed
*/
protected
function
load
(
$key
,
$default
)
{
if
(
$this
->
cacheProvider
->
hasItem
(
$key
))
{
return
$this
->
cacheProvider
->
getItem
(
$key
);
return
$this
->
cacheProvider
->
getItem
(
$key
)
->
get
()
;
}
$value
=
$this
->
repository
->
findOneByKey
(
$key
);
...
...
@@ -84,6 +76,7 @@ class SettingsLoader
// Save value to cache storage
$this
->
save
(
$key
,
$value
->
getValue
());
return
$value
->
getValue
();
}
...
...
@@ -98,16 +91,16 @@ class SettingsLoader
* @param int $lifeTime
* @return bool
*/
protected
function
save
(
$key
,
$value
,
$lifeTime
=
self
::
DEFAULT_LIFE_TIME
)
protected
function
save
(
string
$key
,
$value
,
int
$lifeTime
=
self
::
DEFAULT_LIFE_TIME
)
:
bool
{
if
(
$this
->
cacheProvider
->
hasItem
(
$key
))
{
// Remove old value
$this
->
cacheProvider
->
delete
(
$key
);
}
$item
=
$this
->
cacheProvider
->
getItem
(
$key
);
$item
->
set
(
$value
);
$item
->
expiresAfter
(
$lifeTime
);
return
$this
->
cacheProvider
->
save
(
$item
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment