Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Redis Object Cache
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
Redis Object Cache
Commits
58bfdb6e
Commit
58bfdb6e
authored
11 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Add tracking of cache hits and misses, and the attendant function that the Debug Bar plugin uses.
parent
5355b183
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
object-cache.php
+39
-14
39 additions, 14 deletions
object-cache.php
with
39 additions
and
14 deletions
object-cache.php
+
39
−
14
View file @
58bfdb6e
...
@@ -93,17 +93,6 @@ function wp_cache_get( $key, $group = '' ) {
...
@@ -93,17 +93,6 @@ function wp_cache_get( $key, $group = '' ) {
return
$wp_object_cache
->
get
(
$key
,
$group
);
return
$wp_object_cache
->
get
(
$key
,
$group
);
}
}
/**
* Get server pool statistics.
*
* @return array Array of server statistics, one entry per server.
*/
function
wp_cache_get_stats
()
{
global
$wp_object_cache
;
return
$wp_object_cache
->
stats
();
}
/**
/**
* Increment a numeric item's value.
* Increment a numeric item's value.
*
*
...
@@ -235,6 +224,20 @@ class WP_Object_Cache {
...
@@ -235,6 +224,20 @@ class WP_Object_Cache {
*/
*/
public
$blog_prefix
=
''
;
public
$blog_prefix
=
''
;
/**
* Track how many requests were found in cache
*
* @var int
*/
public
$cache_hits
=
0
;
/**
* Track how may requests were not cached
*
* @var int
*/
public
$cache_misses
=
0
;
/**
/**
* Instantiate the Redis class.
* Instantiate the Redis class.
*
*
...
@@ -384,15 +387,19 @@ class WP_Object_Cache {
...
@@ -384,15 +387,19 @@ class WP_Object_Cache {
if
(
in_array
(
$group
,
$this
->
no_redis_groups
)
)
{
if
(
in_array
(
$group
,
$this
->
no_redis_groups
)
)
{
if
(
isset
(
$this
->
cache
[
$derived_key
]
)
)
{
if
(
isset
(
$this
->
cache
[
$derived_key
]
)
)
{
$this
->
cache_hits
++
;
return
is_object
(
$this
->
cache
[
$derived_key
]
)
?
clone
$this
->
cache
[
$derived_key
]
:
$this
->
cache
[
$derived_key
];
return
is_object
(
$this
->
cache
[
$derived_key
]
)
?
clone
$this
->
cache
[
$derived_key
]
:
$this
->
cache
[
$derived_key
];
}
elseif
(
in_array
(
$group
,
$this
->
no_redis_groups
)
)
{
}
else
{
$this
->
cache_misses
++
;
return
false
;
return
false
;
}
}
}
}
if
(
$this
->
redis
->
exists
(
$derived_key
)
)
{
if
(
$this
->
redis
->
exists
(
$derived_key
)
)
{
$this
->
cache_hits
++
;
$value
=
$this
->
restore_value_from_redis
(
$this
->
redis
->
get
(
$derived_key
)
);
$value
=
$this
->
restore_value_from_redis
(
$this
->
redis
->
get
(
$derived_key
)
);
}
else
{
}
else
{
$this
->
cache_misses
;
return
false
;
return
false
;
}
}
...
@@ -431,8 +438,6 @@ class WP_Object_Cache {
...
@@ -431,8 +438,6 @@ class WP_Object_Cache {
$result
=
$this
->
redis
->
set
(
$derived_key
,
$this
->
prepare_value_for_redis
(
$value
)
);
$result
=
$this
->
redis
->
set
(
$derived_key
,
$this
->
prepare_value_for_redis
(
$value
)
);
}
}
$this
->
add_to_internal_cache
(
$derived_key
,
$value
);
return
$result
;
return
$result
;
}
}
...
@@ -494,6 +499,26 @@ class WP_Object_Cache {
...
@@ -494,6 +499,26 @@ class WP_Object_Cache {
return
$result
;
return
$result
;
}
}
/**
* Render data about current cache requests
*
* @return string
*/
public
function
stats
()
{
?>
<p>
<strong>
Cache Hits:
</strong>
<?php
echo
number_format_i18n
(
$this
->
cache_hits
);
?>
<br
/>
<strong>
Cache Misses:
</strong>
<?php
echo
number_format_i18n
(
$this
->
cache_misses
);
?>
<br
/>
</p>
<p>
</p>
<p><strong>
Caches Retrieved:
</strong></p>
<ul>
<li><em>
prefix:group:key - size in kilobytes
</em></li>
<?php
foreach
(
$this
->
cache
as
$group
=>
$cache
)
:
?>
<li>
<?php
echo
esc_html
(
$group
);
?>
-
<?php
echo
number_format_i18n
(
strlen
(
serialize
(
$cache
)
)
/
1024
,
2
);
?>
kb
</li>
<?php
endforeach
;
?>
</ul>
<?php
}
/**
/**
* Builds a key for the cached object using the blog_id, key, and group values.
* Builds a key for the cached object using the blog_id, key, and group values.
*
*
...
...
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