Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
apc
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
apc
Commits
3f77e08c
Commit
3f77e08c
authored
7 months ago
by
Alberto Paderno
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3463517
: Always check the APCu extension is enabled before calling its functions
parent
90cde162
No related branches found
No related tags found
1 merge request
!28
Issue #3463517: Always check the APCu extension is enabled before calling its functions
Pipeline
#232968
passed
7 months ago
Stage: build
Stage: validate
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
drupal_apc_cache.inc
+51
-37
51 additions, 37 deletions
drupal_apc_cache.inc
with
51 additions
and
37 deletions
drupal_apc_cache.inc
+
51
−
37
View file @
3f77e08c
...
...
@@ -175,7 +175,17 @@ protected function keyName($cid = NULL) {
public
function
get
(
$cid
)
{
$this
->
operations
(
array
(
'get()'
,
$this
->
bin
,
array
(
$cid
)));
return
$this
->
prepareItem
(
apcu_fetch
(
$this
->
keyName
(
$cid
)));
if
(
apcu_enabled
())
{
$data
=
apcu_fetch
(
$this
->
keyName
(
$cid
),
$success
);
if
(
!
$success
)
{
return
FALSE
;
}
return
$this
->
prepareItem
(
$data
);
}
else
{
return
FALSE
;
}
}
/**
...
...
@@ -207,15 +217,17 @@ public function getMultiple(&$cids) {
return
$cache
;
}
foreach
(
$cids
as
$cid
)
{
$data
=
apcu_fetch
(
$this
->
keyName
(
$cid
),
$success
);
if
(
apcu_enabled
())
{
foreach
(
$cids
as
$cid
)
{
$data
=
apcu_fetch
(
$this
->
keyName
(
$cid
),
$success
);
if
(
$success
)
{
$cache
[
$cid
]
=
$this
->
prepareItem
(
$data
);
if
(
$success
)
{
$cache
[
$cid
]
=
$this
->
prepareItem
(
$data
);
}
}
}
$cids
=
array_diff
(
$cids
,
array_keys
(
$cache
));
$cids
=
array_diff
(
$cids
,
array_keys
(
$cache
));
}
return
$cache
;
}
...
...
@@ -227,35 +239,37 @@ public function set($cid, $data, $expire = CACHE_PERMANENT) {
// Add set to statistics.
$this
->
operations
(
array
(
'set()'
,
$this
->
bin
,
$cid
));
// Create new cache object.
$cache
=
new
stdClass
();
$cache
->
cid
=
$cid
;
$cache
->
created
=
REQUEST_TIME
;
$cache
->
expire
=
$expire
;
$cache
->
data
=
$data
;
// Cache values stored in APCu do not need to be serialized, as APCu does
// that.
$cache
->
serialized
=
0
;
switch
(
$expire
)
{
case
CACHE_PERMANENT
:
$ttl
=
0
;
break
;
case
CACHE_TEMPORARY
:
// For apcu_store(), using 0 as TTL means the stored data will never
// expire. The minimum lifetime is one second.
$cache_lifetime
=
variable_get
(
'cache_lifetime'
,
0
);
$ttl
=
$cache_lifetime
>
0
?
$cache_lifetime
:
1
;
break
;
default
:
$ttl
=
$expire
-
time
();
break
;
}
if
(
apcu_enabled
())
{
// Create new cache object.
$cache
=
new
stdClass
();
$cache
->
cid
=
$cid
;
$cache
->
created
=
REQUEST_TIME
;
$cache
->
expire
=
$expire
;
$cache
->
data
=
$data
;
// Cache values stored in APCu do not need to be serialized, as APCu does
// that.
$cache
->
serialized
=
0
;
switch
(
$expire
)
{
case
CACHE_PERMANENT
:
$ttl
=
0
;
break
;
case
CACHE_TEMPORARY
:
// For apcu_store(), using 0 as TTL means the stored data will never
// expire. The minimum lifetime is one second.
$cache_lifetime
=
variable_get
(
'cache_lifetime'
,
0
);
$ttl
=
$cache_lifetime
>
0
?
$cache_lifetime
:
1
;
break
;
default
:
$ttl
=
$expire
-
time
();
break
;
}
apcu_store
(
$this
->
keyName
(
$cid
),
$cache
,
$ttl
);
apcu_store
(
$this
->
keyName
(
$cid
),
$cache
,
$ttl
);
}
}
/**
...
...
@@ -265,7 +279,7 @@ public function set($cid, $data, $expire = CACHE_PERMANENT) {
* The prefix for the cache IDs to delete.
*/
protected
function
deleteKeys
(
$prefix
=
NULL
)
{
if
(
class_exists
(
'APCUIterator'
))
{
if
(
apcu_enabled
()
&&
class_exists
(
'APCUIterator'
))
{
$escaped_key
=
preg_quote
(
$this
->
keyName
(
$prefix
),
'/'
);
$iterator
=
new
APCUIterator
(
"/^
$escaped_key
/"
,
APC_ITER_KEY
);
apcu_delete
(
$iterator
);
...
...
@@ -314,7 +328,7 @@ public function clear($cid = NULL, $wildcard = FALSE) {
* {@inheritdoc}
*/
public
function
isEmpty
()
{
if
(
class_exists
(
'APCUIterator'
))
{
if
(
apcu_enabled
()
&&
class_exists
(
'APCUIterator'
))
{
$escaped_key
=
preg_quote
(
$this
->
keyName
(),
'/'
);
$iterator
=
new
APCUIterator
(
'/^'
.
$escaped_key
.
'/'
,
APC_ITER_KEY
);
...
...
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