Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
WP Plugins
Redis Page Cache
Commits
d807ddfa
Commit
d807ddfa
authored
Feb 26, 2014
by
Erick Hitter
Browse files
Cache distinctly for mobile and tablet visitors
parent
a64ce00e
Changes
1
Hide whitespace changes
Inline
Side-by-side
index-wp-redis.php
View file @
d807ddfa
...
...
@@ -42,11 +42,9 @@ if ( $wp_redis_cache_config['debug'] ) {
}
/**
*
MOBILE HANDLING
*
SET SEPARATE CACHES FOR BROAD DEVICE TYPES
*/
if
(
wp_redis_cache_is_mobile_request
()
)
{
$wp_redis_cache_config
[
'redis_key'
]
=
'MO-'
.
$wp_redis_cache_config
[
'redis_key'
];
}
$wp_redis_cache_config
[
'redis_key'
]
=
wp_redis_cache_set_device_key
(
$wp_redis_cache_config
[
'redis_key'
]
);
/**
* UTILITY FUNCTIONS
...
...
@@ -119,10 +117,66 @@ function wp_redis_cache_get_clean_url( $secret ) {
}
/**
* Prefix cache key if device calls for separate caching
*
* @param string $key
* @return $string
*/
function
wp_redis_cache_set_device_key
(
$key
)
{
switch
(
wp_redis_cache_get_device_type
()
)
{
case
'tablet'
:
$prefix
=
'T-'
;
break
;
case
'mobile'
:
$prefix
=
'M-'
;
break
;
default
:
case
'desktop'
:
$prefix
=
''
;
break
;
}
return
$prefix
.
$key
;
}
/**
* Determine the current device type from its user agent
* Allows for separate caches for tablet, mobile, and desktop visitors
*
* @return string
*/
function
wp_redis_cache_is_mobile_request
()
{
return
false
;
function
wp_redis_cache_get_device_type
()
{
$ua
=
$_SERVER
[
'HTTP_USER_AGENT'
];
if
(
empty
(
$ua
)
)
{
return
'desktop'
;
}
// Tablet user agents
if
(
false
!==
stripos
(
$ua
,
'ipad'
)
||
(
false
!==
stripos
(
$ua
,
'Android'
)
&&
false
===
stripos
(
$ua
,
'mobile'
)
)
||
false
!==
stripos
(
$ua
,
'tablet '
)
||
false
!==
stripos
(
$ua
,
'Silk/'
)
||
false
!==
stripos
(
$ua
,
'Kindle'
)
||
false
!==
stripos
(
$ua
,
'PlayBook'
)
||
false
!==
stripos
(
$ua
,
'RIM Tablet'
)
||
)
{
return
'tablet'
;
}
// Mobile user agents
if
(
false
!==
stripos
(
$ua
,
'Mobile'
)
||
// many mobile devices (all iPhone, iPad, etc.)
false
!==
stripos
(
$ua
,
'Android'
)
||
false
!==
stripos
(
$ua
,
'BlackBerry'
)
||
false
!==
stripos
(
$ua
,
'Opera Mini'
)
||
false
!==
stripos
(
$ua
,
'Opera Mobi'
)
)
{
return
'mobile'
;
}
return
'desktop'
;
}
/**
...
...
@@ -143,10 +197,10 @@ function wp_redis_cache_connect_redis() {
$redis
=
new
Redis
();
// Sockets can be used as well. Documentation @ https://github.com/nicolasff/phpredis/#connection
$redis
->
connect
(
$wp_redis_cache_config
[
'redis_server'
],
$wp_redis_cache_config
[
'redis_port'
]
);
$redis
->
select
(
$wp_redis_cache_config
[
'redis_db'
]
);
}
else
{
// Fallback to predis5.2.php
// Fallback to predis5.2.php
}
else
{
if
(
$wp_redis_cache_config
[
'debug'
]
)
{
$wp_redis_cache_config
[
'debug_messages'
]
.
=
"<!-- using predis as a backup -->
\n
"
;
}
...
...
Write
Preview
Supports
Markdown
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