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
054c48f6
Commit
054c48f6
authored
11 years ago
by
Hendrik Klemp
Browse files
Options
Downloads
Patches
Plain Diff
Add Clear cache Button to Options Page
parent
0bc66a24
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
index-wp-redis.php
+2
-2
2 additions, 2 deletions
index-wp-redis.php
wp-redis-cache/cache.php
+61
-13
61 additions, 13 deletions
wp-redis-cache/cache.php
wp-redis-cache/options.php
+1
-1
1 addition, 1 deletion
wp-redis-cache/options.php
with
64 additions
and
16 deletions
index-wp-redis.php
+
2
−
2
View file @
054c48f6
...
@@ -55,7 +55,7 @@ try {
...
@@ -55,7 +55,7 @@ try {
}
else
if
(
$redis
->
exists
(
$redis_key
))
{
}
else
if
(
$redis
->
exists
(
$redis_key
))
{
$cache
=
true
;
$cache
=
true
;
$html_of_page
=
$redis
->
get
(
$redis_key
);
$html_of_page
=
$redis
->
get
(
$redis_key
);
echo
$html_of_page
;
echo
$html_of_page
;
// If the cache does not exist lets display the user the normal page without cache, and then fetch a new cache page
// If the cache does not exist lets display the user the normal page without cache, and then fetch a new cache page
}
else
if
(
$_SERVER
[
'REMOTE_ADDR'
]
!=
$ip_of_your_website
&&
strstr
(
$current_url
,
'preview=true'
)
==
false
)
{
}
else
if
(
$_SERVER
[
'REMOTE_ADDR'
]
!=
$ip_of_your_website
&&
strstr
(
$current_url
,
'preview=true'
)
==
false
)
{
...
@@ -68,7 +68,7 @@ try {
...
@@ -68,7 +68,7 @@ try {
require
(
'./wp-blog-header.php'
);
require
(
'./wp-blog-header.php'
);
$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
;
$unlimited
=
get_option
(
'wp-redis-cache-debug'
,
false
);
$unlimited
=
get_option
(
'wp-redis-cache-debug'
,
false
);
$seconds_cache_redis
=
get_option
(
'wp-redis-cache-seconds'
,
43200
);
$seconds_cache_redis
=
get_option
(
'wp-redis-cache-seconds'
,
43200
);
...
...
This diff is collapsed.
Click to expand it.
wp-redis-cache/cache.php
+
61
−
13
View file @
054c48f6
<?php
<?php
add_action
(
'transition_post_status'
,
'refresh_wp_redis_cache'
,
10
,
3
);
add_action
(
'transition_post_status'
,
'refresh_wp_redis_cache'
,
10
,
3
);
add_action
(
'wp_ajax_clear_wp_redis_cache'
,
'clear_wp_redis_cache'
);
add_action
(
'admin_footer'
,
'clear_wp_redis_cache_javascript'
);
//clears the cache after you update a post
//clears the cache after you update a post
function
refresh_wp_redis_cache
(
$new
,
$old
,
$post
)
function
refresh_wp_redis_cache
(
$new
,
$old
,
$post
)
{
{
if
(
$new
==
"publish"
)
if
(
$new
==
"publish"
)
{
{
$permalink
=
get_permalink
(
$post
->
ID
);
$permalink
=
get_permalink
(
$post
->
ID
);
// aaronstpierre: this needs to be include_once so as not to cauase a redeclaration error
include_once
(
"predis5.2.php"
);
//we need this to use Redis inside of PHP
$redis
=
new
Predis_Client
();
// aaronstpierre: this needs to be include_once so as not to cauase a redeclaration error
$redis_key
=
md5
(
$permalink
);
include_once
(
"predis5.2.php"
);
//we need this to use Redis inside of PHP
$redis
->
del
(
$redis_key
);
$redis
=
new
Predis_Client
();
//refresh the front page
$frontPage
=
get_home_url
()
.
"/"
;
$redis_key
=
md5
(
$frontPage
);
$redis
->
del
(
$redis_key
);
}
}
$redis_key
=
md5
(
$permalink
);
// clears the whole cache
$redis
->
del
(
$redis_key
);
function
clear_wp_redis_cache
()
{
include_once
(
"predis5.2.php"
);
//we need this to use Redis inside of PHP
$args
=
array
(
'post_type'
=>
'any'
,
'posts_per_page'
=>
-
1
);
$wp_query
=
new
WP_Query
(
$args
);
// to get all Posts
$redis
=
new
Predis_Client
();
// Loop all posts and clear the cache
$i
=
0
;
while
(
$wp_query
->
have_posts
()
)
:
$wp_query
->
the_post
();
$permalink
=
get_permalink
();
//refresh the front page
$redis_key
=
md5
(
$permalink
);
$frontPage
=
get_home_url
()
.
"/"
;
if
((
$redis
->
exists
(
$redis_key
))
==
true
)
{
$redis_key
=
md5
(
$frontPage
);
$redis
->
del
(
$redis_key
);
$redis
->
del
(
$redis_key
);
$i
++
;
}
endwhile
;
echo
$i
++.
" of "
.
$wp_query
->
found_posts
.
" posts was cleared in cache"
;
die
();
}
}
function
clear_wp_redis_cache_javascript
()
{
?>
<script
type=
"text/javascript"
>
jQuery
(
document
).
ready
(
function
(
$
)
{
jQuery
(
'
#WPRedisClearCache
'
).
click
(
function
(){
var
data
=
{
action
:
'
clear_wp_redis_cache
'
,
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
$
.
post
(
ajaxurl
,
data
,
function
(
response
)
{
alert
(
response
);
});
});
});
</script>
<?php
}
}
?>
This diff is collapsed.
Click to expand it.
wp-redis-cache/options.php
+
1
−
1
View file @
054c48f6
...
@@ -143,7 +143,7 @@ function edit_redis_options() {
...
@@ -143,7 +143,7 @@ function edit_redis_options() {
<input
type=
"checkbox"
name=
"wp-redis-cache-unlimited"
size=
"45"
value=
"true"
<?php
checked
(
'true'
,
get_option
(
'wp-redis-cache-unlimited'
));
?>
/></p>
<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>
<p><input
type=
"button"
id=
"WPRedisClearCache"
name=
"WPRedisClearCache"
value=
"Clear Cache"
></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-cache-unlimited"
/>
<input
type=
"hidden"
name=
"page_options"
value=
"wp-redis-cache-seconds,wp-redis-cache-unlimited"
/>
...
...
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