Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
PSDI Army
yii2
Commits
0ab5bbaf
Commit
0ab5bbaf
authored
May 26, 2013
by
votintsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Cache.php
Moved add prefix ($this->keyPrefix) to the key in function buildKey(). Could it be better?
parent
ead91417
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
Cache.php
framework/yii/caching/Cache.php
+9
-8
No files found.
framework/yii/caching/Cache.php
View file @
0ab5bbaf
...
@@ -98,15 +98,16 @@ abstract class Cache extends Component implements \ArrayAccess
...
@@ -98,15 +98,16 @@ abstract class Cache extends Component implements \ArrayAccess
* ~~~
* ~~~
*
*
* @param array|string $key the key to be normalized
* @param array|string $key the key to be normalized
* @return string the generated cache key
* @return string the generated cache key
include $this->keyPrefix
*/
*/
public
function
buildKey
(
$key
)
public
function
buildKey
(
$key
)
{
{
if
(
is_string
(
$key
))
{
if
(
is_string
(
$key
))
{
return
ctype_alnum
(
$key
)
&&
StringHelper
::
strlen
(
$key
)
<=
32
?
$key
:
md5
(
$key
);
$key
=
ctype_alnum
(
$key
)
&&
StringHelper
::
strlen
(
$key
)
<=
32
?
$key
:
md5
(
$key
);
}
else
{
}
else
{
return
md5
(
json_encode
(
$key
));
$key
=
md5
(
json_encode
(
$key
));
}
}
return
$this
->
keyPrefix
.
$key
;
}
}
/**
/**
...
@@ -117,7 +118,7 @@ abstract class Cache extends Component implements \ArrayAccess
...
@@ -117,7 +118,7 @@ abstract class Cache extends Component implements \ArrayAccess
*/
*/
public
function
get
(
$key
)
public
function
get
(
$key
)
{
{
$key
=
$this
->
keyPrefix
.
$this
->
buildKey
(
$key
);
$key
=
$this
->
buildKey
(
$key
);
$value
=
$this
->
getValue
(
$key
);
$value
=
$this
->
getValue
(
$key
);
if
(
$value
===
false
||
$this
->
serializer
===
false
)
{
if
(
$value
===
false
||
$this
->
serializer
===
false
)
{
return
$value
;
return
$value
;
...
@@ -147,7 +148,7 @@ abstract class Cache extends Component implements \ArrayAccess
...
@@ -147,7 +148,7 @@ abstract class Cache extends Component implements \ArrayAccess
{
{
$keyMap
=
array
();
$keyMap
=
array
();
foreach
(
$keys
as
$key
)
{
foreach
(
$keys
as
$key
)
{
$keyMap
[
$key
]
=
$this
->
keyPrefix
.
$this
->
buildKey
(
$key
);
$keyMap
[
$key
]
=
$this
->
buildKey
(
$key
);
}
}
$values
=
$this
->
getValues
(
array_values
(
$keyMap
));
$values
=
$this
->
getValues
(
array_values
(
$keyMap
));
$results
=
array
();
$results
=
array
();
...
@@ -192,7 +193,7 @@ abstract class Cache extends Component implements \ArrayAccess
...
@@ -192,7 +193,7 @@ abstract class Cache extends Component implements \ArrayAccess
}
elseif
(
$this
->
serializer
!==
false
)
{
}
elseif
(
$this
->
serializer
!==
false
)
{
$value
=
call_user_func
(
$this
->
serializer
[
0
],
array
(
$value
,
$dependency
));
$value
=
call_user_func
(
$this
->
serializer
[
0
],
array
(
$value
,
$dependency
));
}
}
$key
=
$this
->
keyPrefix
.
$this
->
buildKey
(
$key
);
$key
=
$this
->
buildKey
(
$key
);
return
$this
->
setValue
(
$key
,
$value
,
$expire
);
return
$this
->
setValue
(
$key
,
$value
,
$expire
);
}
}
...
@@ -217,7 +218,7 @@ abstract class Cache extends Component implements \ArrayAccess
...
@@ -217,7 +218,7 @@ abstract class Cache extends Component implements \ArrayAccess
}
elseif
(
$this
->
serializer
!==
false
)
{
}
elseif
(
$this
->
serializer
!==
false
)
{
$value
=
call_user_func
(
$this
->
serializer
[
0
],
array
(
$value
,
$dependency
));
$value
=
call_user_func
(
$this
->
serializer
[
0
],
array
(
$value
,
$dependency
));
}
}
$key
=
$this
->
keyPrefix
.
$this
->
buildKey
(
$key
);
$key
=
$this
->
buildKey
(
$key
);
return
$this
->
addValue
(
$key
,
$value
,
$expire
);
return
$this
->
addValue
(
$key
,
$value
,
$expire
);
}
}
...
@@ -228,7 +229,7 @@ abstract class Cache extends Component implements \ArrayAccess
...
@@ -228,7 +229,7 @@ abstract class Cache extends Component implements \ArrayAccess
*/
*/
public
function
delete
(
$key
)
public
function
delete
(
$key
)
{
{
$key
=
$this
->
keyPrefix
.
$this
->
buildKey
(
$key
);
$key
=
$this
->
buildKey
(
$key
);
return
$this
->
deleteValue
(
$key
);
return
$this
->
deleteValue
(
$key
);
}
}
...
...
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