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
50fded33
Commit
50fded33
authored
11 years ago
by
Hendrik Klemp
Browse files
Options
Downloads
Patches
Plain Diff
Add Unlimited Cache
- Add Debug Mode - Add Unlimited Cache - Clean up code - Don't cache Search Sites
parent
4ed79941
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
index-wp-redis.php
+34
-15
34 additions, 15 deletions
index-wp-redis.php
wp-redis-cache/options.php
+6
-4
6 additions, 4 deletions
wp-redis-cache/options.php
with
40 additions
and
19 deletions
index-wp-redis.php
+
34
−
15
View file @
50fded33
...
@@ -9,21 +9,24 @@ function getMicroTime($t)
...
@@ -9,21 +9,24 @@ function getMicroTime($t)
return
((
float
)
$usec
+
(
float
)
$sec
);
return
((
float
)
$usec
+
(
float
)
$sec
);
}
}
// 12 hours by default, you can change in this in wp-admin options page
$seconds_cache_redis
=
60
*
60
*
12
;
//You must set this to the IP of your website
$debug
=
false
;
$ip_of_your_website
=
'127.0.0.1'
;
/*This is if you want to manually refresh the cache
$ip_of_your_website
=
'127.0.0.1'
;
ex: http://example.com/sample-post?refresh=changeme */
$secret_string
=
'changeme'
;
$secret_string
=
"changeme"
;
if
(
!
defined
(
'WP_USE_THEMES'
))
{
define
(
'WP_USE_THEMES'
,
true
);
}
// so we don't confuse the cloudflare server
// so we don't confuse the cloudflare server
if
(
isset
(
$_SERVER
[
'HTTP_CF_CONNECTING_IP'
]))
{
if
(
isset
(
$_SERVER
[
'HTTP_CF_CONNECTING_IP'
]))
{
$_SERVER
[
'REMOTE_ADDR'
]
=
$_SERVER
[
'HTTP_CF_CONNECTING_IP'
];
$_SERVER
[
'REMOTE_ADDR'
]
=
$_SERVER
[
'HTTP_CF_CONNECTING_IP'
];
}
}
if
(
!
defined
(
'WP_USE_THEMES'
))
{
if
(
!
defined
(
'WP_USE_THEMES'
))
{
define
(
'WP_USE_THEMES'
,
true
);
define
(
'WP_USE_THEMES'
,
true
);
}
}
...
@@ -68,16 +71,25 @@ try {
...
@@ -68,16 +71,25 @@ try {
$html_of_page
=
ob_get_contents
();
$html_of_page
=
ob_get_contents
();
ob_end_clean
();
ob_end_clean
();
echo
$html_of_page
;
echo
$html_of_page
;
//if the user has the seconds defined in the admin section use it
$unlimited
=
get_option
(
'wp-redis-cache-debug'
,
false
);
$usr_seconds
=
get_option
(
'wp-redis-cache-seconds'
);
$seconds_cache_redis
=
get_option
(
'wp-redis-cache-seconds'
,
43200
);
if
(
isset
(
$usr_seconds
)
&&
is_numeric
(
$usr_seconds
))
{
if
(
!
is_numeric
(
$seconds_cache_redis
))
{
$seconds_cache_redis
=
$usr_seconds
;
$seconds_cache_redis
=
43200
;
}
}
// When a page displays after an "HTTP 404: Not Found" error occurs, do not cache
// When a page displays after an "HTTP 404: Not Found" error occurs, do not cache
if
(
!
is_404
())
{
// When the search was used, do not cache
$redis
->
setex
(
$redis_key
,
$seconds_cache_redis
,
$html_of_page
);
if
(
!
is_404
()
&&
!
is_search
())
{
if
(
$unlimited
)
{
$redis
->
setex
(
$redis_key
,
$html_of_page
);
}
else
{
$redis
->
setex
(
$redis_key
,
$seconds_cache_redis
,
$html_of_page
);
}
}
}
}
else
//either the user is logged in, or is posting a comment, show them uncached
}
else
//either the user is logged in, or is posting a comment, show them uncached
{
{
...
@@ -99,4 +111,11 @@ if ($_SERVER['REMOTE_ADDR'] != $ip_of_your_website) {
...
@@ -99,4 +111,11 @@ if ($_SERVER['REMOTE_ADDR'] != $ip_of_your_website) {
$end
=
microtime
();
$end
=
microtime
();
$time
=
(
@
getMicroTime
(
$end
)
-
@
getMicroTime
(
$start
));
$time
=
(
@
getMicroTime
(
$end
)
-
@
getMicroTime
(
$start
));
echo
"<!-- Cache system by Benjamin Adams. Page generated in "
.
round
(
$time
,
5
)
.
" seconds. -->"
;
echo
"<!-- Cache system by Benjamin Adams. Page generated in "
.
round
(
$time
,
5
)
.
" seconds. -->"
;
if
(
$debug
)
{
echo
"<!-- wp-redis-cache-seconds = "
.
$seconds_cache_redis
.
" -->"
;
echo
"<!-- wp-redis-cache-secret = "
.
$secret_string
.
"-->"
;
echo
"<!-- wp-redis-cache-ip = "
.
$ip_of_your_website
.
"-->"
;
echo
"<!-- wp-redis-cache-unlimited = "
.
$unlimited
.
"-->"
;
echo
"<!-- wp-redis-cache-debug = "
.
$debug
.
"-->"
;
}
}
}
This diff is collapsed.
Click to expand it.
wp-redis-cache/options.php
+
6
−
4
View file @
50fded33
...
@@ -137,13 +137,15 @@ function edit_redis_options() {
...
@@ -137,13 +137,15 @@ function edit_redis_options() {
<p><strong>
Seconds of Caching:
</strong><br
/>
<p><strong>
Seconds of Caching:
</strong><br
/>
How many seconds would you like to cache? *Recommended 12 hours or 43200 seconds
<br
/>
How many seconds would you like to cache? *Recommended 12 hours or 43200 seconds
<br
/>
<input
type=
"text"
name=
"wp-redis-cache-seconds"
size=
"45"
value=
"
<?php
echo
get_option
(
'wp-redis-cache-seconds'
);
?>
"
/></p>
<input
type=
"text"
name=
"wp-redis-cache-seconds"
size=
"45"
value=
"
<?php
echo
get_option
(
'wp-redis-cache-seconds'
);
?>
"
/></p>
<p><strong>
Cache unlimeted:
</strong><br
/>
If this options set the cache never expire. This option overiedes the setting "Seconds of Caching"
<br
/>
<input
type=
"checkbox"
name=
"wp-redis-cache-unlimited"
size=
"45"
value=
"true"
<?php
checked
(
'true'
,
get_option
(
'wp-redis-cache-unlimited'
));
?>
/></p>
<p><input
type=
"submit"
name=
"Submit"
value=
"Update Options"
/></p>
<p><input
type=
"submit"
name=
"Submit"
value=
"Update Options"
/></p>
<input
type=
"hidden"
name=
"action"
value=
"update"
/>
<input
type=
"hidden"
name=
"action"
value=
"update"
/>
<input
type=
"hidden"
name=
"page_options"
value=
"wp-redis-cache-seconds,wp-redis-
secret
"
/>
<input
type=
"hidden"
name=
"page_options"
value=
"wp-redis-cache-seconds,wp-redis-
cache-unlimited
"
/>
</form>
</form>
</div>
</div>
...
...
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