Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Redis Page 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 Page Cache
Commits
0ca5e34c
Commit
0ca5e34c
authored
11 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
PHPDoc and some simplification of the URL cleaner
parent
6aec566c
Branches
Branches containing commit
Tags
Tags containing commit
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
index-wp-redis.php
+47
-3
47 additions, 3 deletions
index-wp-redis.php
with
47 additions
and
3 deletions
index-wp-redis.php
+
47
−
3
View file @
0ca5e34c
...
...
@@ -26,6 +26,8 @@ function wp_redis_cache_exception_handler( $exception ) {
}
/**
* END GLOBAL CONFIGURATION
*
* DO NOT EDIT BELOW THIS LINE!
*/
$GLOBALS
[
'wp_redis_cache_config'
][
'current_url'
]
=
wp_redis_cache_get_clean_url
(
$GLOBALS
[
'wp_redis_cache_config'
][
'secret_string'
]
);
...
...
@@ -34,19 +36,43 @@ $GLOBALS['wp_redis_cache_config']['redis_key'] = md5( $GLOBALS['wp_redis_cache
// Start the timer so we can track the page load time
$start
=
microtime
();
/**
* UTILITY FUNCTIONS
*/
/**
* Compute microtime from a timestamp
*
* @return float
*/
function
wp_redis_cache_get_micro_time
(
$time
)
{
list
(
$usec
,
$sec
)
=
explode
(
" "
,
$time
);
return
(
(
float
)
$usec
+
(
float
)
$sec
);
}
/**
* Is the current request a refresh request with the correct secret key?
*
* @return bool
*/
function
wp_redis_cache_refresh_has_secret
(
$secret
)
{
return
isset
(
$_GET
[
'refresh'
]
)
&&
$secret
==
$_GET
[
'refresh'
];
}
/**
* Does current request include a refresh request?
*
* @return bool
*/
function
wp_redis_cache_request_has_secret
(
$secret
)
{
return
false
!==
strpos
(
$_SERVER
[
'REQUEST_URI'
],
"refresh=${secret}"
);
}
/**
* Determine if request is from a server other than the one running this code
*
* @return bool
*/
function
wp_redis_cache_is_remote_page_load
(
$current_url
,
$server_ip
)
{
return
(
isset
(
$_SERVER
[
'HTTP_REFERER'
]
)
&&
$_SERVER
[
'HTTP_REFERER'
]
==
$current_url
...
...
@@ -54,6 +80,11 @@ function wp_redis_cache_is_remote_page_load( $current_url, $server_ip ) {
&&
$_SERVER
[
'REMOTE_ADDR'
]
!=
$server_ip
);
}
/**
* Set proper IP address for proxied requests
*
* @return null
*/
function
wp_redis_cache_handle_cdn_remote_addressing
()
{
// so we don't confuse the cloudflare server
if
(
isset
(
$_SERVER
[
'HTTP_CF_CONNECTING_IP'
]
)
)
{
...
...
@@ -61,15 +92,28 @@ function wp_redis_cache_handle_cdn_remote_addressing() {
}
}
/**
* Prepare a URL for use as a cache key
*
* Strips secret key from URL
*
* @param string
* @return string
*/
function
wp_redis_cache_get_clean_url
(
$secret
)
{
$replace_keys
=
array
(
"?refresh=${secret}"
,
"&refresh=${secret}"
);
$url
=
"http://${_SERVER['HTTP_HOST']}${_SERVER['REQUEST_URI']}"
;
$current_url
=
str_replace
(
$replace_keys
,
''
,
$url
);
return
$current_url
;
$url
=
'http://'
.
$_SERVER
[
'HTTP_HOST'
]
.
$_SERVER
[
'REQUEST_URI'
];
return
str_replace
(
$replace_keys
,
''
,
$url
);
}
/**
* BEGIN CACHING LOGIC
*/
// Set proper IP for proxied requests
wp_redis_cache_handle_cdn_remote_addressing
();
// Ensure WP uses a theme (this is normally set in index.php)
if
(
!
defined
(
'WP_USE_THEMES'
)
)
{
define
(
'WP_USE_THEMES'
,
true
);
}
...
...
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