Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
php_utils
Project
Project
Details
Activity
Releases
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
bp
php_utils
Commits
8da7c83f
Commit
8da7c83f
authored
Jul 23, 2021
by
cuiweifeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update : delete json_decode
parent
5f2c1cf1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
50 deletions
+4
-50
CacheUtil.php
src/Cache/CacheUtil.php
+4
-50
No files found.
src/Cache/CacheUtil.php
View file @
8da7c83f
...
...
@@ -74,36 +74,6 @@ class CacheUtil
return
call_user_func_array
([
$this
->
handler
,
$method
],
$args
);
}
/**
* 获取原始数据
* @param $key
* @return mixed
*/
public
function
getUnChange
(
$key
,
$prefix
=
''
){
return
$this
->
handler
->
get
(
$this
->
getCacheKey
(
$prefix
,
$key
));
}
/**
* 保存原始数据
* @param $key
* @param $value
* @param $expire
* @return mixed
*/
public
function
setUnChange
(
$key
,
$value
,
$expire
=
null
,
$prefix
=
''
){
if
(
is_null
(
$expire
))
{
// $expire = $this->expire;
return
false
;
}
$key
=
$this
->
getCacheKey
(
$prefix
,
$key
);
if
(
is_int
(
$expire
)
&&
$expire
)
{
$result
=
$this
->
handler
->
setex
(
$key
,
$expire
,
$value
);
}
else
{
$result
=
$this
->
handler
->
set
(
$key
,
$value
);
}
return
$result
;
}
/**
* 读取缓存
* @access public
...
...
@@ -117,9 +87,7 @@ class CacheUtil
if
(
is_null
(
$value
)
||
false
===
$value
)
{
return
$default
;
}
$jsonData
=
json_decode
(
$value
,
true
);
// 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据
return
(
null
===
$jsonData
)
?
$value
:
$jsonData
;
return
$value
;
}
/**
...
...
@@ -129,24 +97,13 @@ class CacheUtil
* @param mixed $default 默认值
* @return mixed
*/
public
function
gets
(
$keys
,
$prefix
=
''
,
$default
=
false
)
public
function
gets
(
$keys
,
$prefix
=
''
)
{
if
(
empty
(
$keys
)
||
!
is_array
(
$keys
))
{
return
$default
;
return
false
;
}
$keys
=
array_values
(
$keys
);
$values
=
$this
->
handler
->
mGet
(
$this
->
getCacheKey
(
$prefix
,
$keys
));
if
(
is_null
(
$values
)
||
false
===
$values
)
{
return
$default
;
}
$result
=
[];
foreach
((
array
)
$values
as
$i
=>
$value
)
{
if
(
$value
!==
false
)
{
$jsonData
=
json_decode
(
$value
,
true
);
$result
[
$keys
[
$i
]]
=
(
null
===
$jsonData
)
?
$value
:
$jsonData
;
}
}
return
$result
;
return
$this
->
handler
->
mGet
(
$this
->
getCacheKey
(
$prefix
,
$keys
));
}
/**
...
...
@@ -165,7 +122,6 @@ class CacheUtil
}
$key
=
$this
->
getCacheKey
(
$prefix
,
$key
);
//对数组/对象数据进行缓存处理,保证数据完整性
$value
=
(
is_object
(
$value
)
||
is_array
(
$value
))
?
json_encode
(
$value
)
:
$value
;
if
(
is_int
(
$expire
)
&&
$expire
)
{
$result
=
$this
->
handler
->
setex
(
$key
,
$expire
,
$value
);
}
else
{
...
...
@@ -189,7 +145,6 @@ class CacheUtil
$this
->
handler
->
multi
();
foreach
(
$items
as
$key
=>
$value
)
{
$key
=
$this
->
getCacheKey
(
$prefix
,
$key
);
$value
=
(
is_object
(
$value
)
||
is_array
(
$value
))
?
json_encode
(
$value
)
:
$value
;
$this
->
handler
->
setex
(
$key
,
$expire
,
$value
);
}
return
$this
->
handler
->
exec
();
...
...
@@ -210,7 +165,6 @@ class CacheUtil
}
$key
=
$this
->
getCacheKey
(
$prefix
,
$key
);
//对数组/对象数据进行缓存处理,保证数据完整性
$value
=
(
is_object
(
$value
)
||
is_array
(
$value
))
?
json_encode
(
$value
)
:
$value
;
if
(
is_int
(
$expire
)
&&
$expire
)
{
$result
=
$this
->
handler
->
setenx
(
$key
,
$expire
,
$value
);
}
else
{
...
...
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