Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
R
Redis Page Cache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WP Plugins
Redis Page Cache
Commits
1ca474a7
Commit
1ca474a7
authored
Feb 27, 2014
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Capture additional headers, and allow others through via a whitelist.
See
#3
.
parent
63b01d13
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
14 deletions
+50
-14
index-redis-page-cache.php
index-redis-page-cache.php
+50
-14
No files found.
index-redis-page-cache.php
View file @
1ca474a7
...
...
@@ -37,8 +37,9 @@ $redis_page_cache_config = array(
'redis_server'
=>
'127.0.0.1'
,
'redis_port'
=>
6379
,
'redis_db'
=>
0
,
'cache_version'
=>
1
,
'cache_version'
=>
0
,
'cache_headers'
=>
true
,
'additional_headers'
=>
array
(
'link'
,
'x-hacker'
,
'x-pingback'
),
'secret_string'
=>
'changeme'
,
);
...
...
@@ -275,6 +276,9 @@ if ( ! defined( 'WP_USE_THEMES' ) ) {
define
(
'WP_USE_THEMES'
,
true
);
}
// Set a header advertising the cache engine
header
(
'X-Redis-Page-Cache: Redis Page Cache for WordPress by Erick Hitter (http://eth.pw/rpc)'
,
true
);
try
{
// Establish connection with Redis server
$redis
=
redis_page_cache_connect_redis
();
...
...
@@ -311,6 +315,13 @@ try {
// Retrieve cached page, which is an array that includes meta data along with the page output
$cache
=
unserialize
(
$redis
->
get
(
$redis_page_cache_config
[
'redis_key'
]
)
);
// Output cached headers from original page
if
(
!
empty
(
$cache
[
'headers'
]
)
)
{
foreach
(
$cache
[
'headers'
]
as
$key
=>
$value
)
{
header
(
"
{
$key
}
:
{
$value
}
"
,
true
);
}
}
// Output cache headers if desired
if
(
$redis_page_cache_config
[
'cache_headers'
]
)
{
header
(
'Last-Modified: '
.
gmdate
(
'D, d M Y H:i:s'
,
$cache
[
'time'
]
)
.
' GMT'
,
true
);
...
...
@@ -360,12 +371,37 @@ try {
// Cache rendered page if appropriate
if
(
!
is_404
()
&&
!
is_search
()
)
{
// Default cache payload
$cache
=
array
(
'output'
=>
$output
,
'time'
=>
time
(),
'age'
=>
31536000
,
// one year in seconds
'headers'
=>
array
(),
);
// Capture certain headers
// Props to @andy and Batcache (http://wordpress.org/plugins/batcache/) for this code
if
(
!
empty
(
$redis_page_cache_config
[
'additional_headers'
]
)
)
{
if
(
function_exists
(
'headers_list'
)
)
{
foreach
(
headers_list
()
as
$header
)
{
list
(
$key
,
$value
)
=
array_map
(
'trim'
,
explode
(
':'
,
$header
,
2
)
);
$cache
[
'headers'
][
$key
]
=
$value
;
}
}
elseif
(
function_exists
(
'apache_response_headers'
)
)
{
$cache
[
'headers'
]
=
apache_response_headers
();
}
if
(
$cache
[
'headers'
]
)
{
foreach
(
$cache
[
'headers'
]
as
$key
=>
$value
)
{
if
(
!
in_array
(
strtolower
(
$key
),
$redis_page_cache_config
[
'additional_headers'
]
)
)
unset
(
$cache
[
'headers'
][
$key
]
);
}
}
unset
(
$key
);
unset
(
$value
);
}
// Is unlimited cache life requested?
if
(
!
isset
(
$redis_page_cache_config
[
'unlimited'
]
)
)
{
$redis_page_cache_config
[
'unlimited'
]
=
(
bool
)
get_option
(
'redis-page-cache-debug'
,
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment