Always pass integer expirations to cache backends.

props SergeyBiryukov, andreasnrb.
fixes #25308.


git-svn-id: https://develop.svn.wordpress.org/trunk@25451 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2013-09-16 17:42:49 +00:00
parent a58d80bbc1
commit 80653c01a1
2 changed files with 13 additions and 11 deletions

View File

@ -21,10 +21,10 @@
* @param int $expire When the cache data should be expired * @param int $expire When the cache data should be expired
* @return bool False if cache key and group already exist, true on success * @return bool False if cache key and group already exist, true on success
*/ */
function wp_cache_add($key, $data, $group = '', $expire = 0) { function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache; global $wp_object_cache;
return $wp_object_cache->add($key, $data, $group, $expire); return $wp_object_cache->add( $key, $data, $group, (int) $expire );
} }
/** /**
@ -154,10 +154,10 @@ function wp_cache_init() {
* @param int $expire When to expire the cache contents * @param int $expire When to expire the cache contents
* @return bool False if not exists, true if contents were replaced * @return bool False if not exists, true if contents were replaced
*/ */
function wp_cache_replace($key, $data, $group = '', $expire = 0) { function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache; global $wp_object_cache;
return $wp_object_cache->replace($key, $data, $group, $expire); return $wp_object_cache->replace( $key, $data, $group, (int) $expire );
} }
/** /**
@ -173,10 +173,10 @@ function wp_cache_replace($key, $data, $group = '', $expire = 0) {
* @param int $expire When to expire the cache contents * @param int $expire When to expire the cache contents
* @return bool False on failure, true on success * @return bool False on failure, true on success
*/ */
function wp_cache_set($key, $data, $group = '', $expire = 0) { function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache; global $wp_object_cache;
return $wp_object_cache->set($key, $data, $group, $expire); return $wp_object_cache->set( $key, $data, $group, (int) $expire );
} }
/** /**
@ -320,7 +320,7 @@ class WP_Object_Cache {
* @param int $expire When to expire the cache contents * @param int $expire When to expire the cache contents
* @return bool False if cache key and group already exist, true on success * @return bool False if cache key and group already exist, true on success
*/ */
function add( $key, $data, $group = 'default', $expire = '' ) { function add( $key, $data, $group = 'default', $expire = 0 ) {
if ( wp_suspend_cache_addition() ) if ( wp_suspend_cache_addition() )
return false; return false;
@ -334,7 +334,7 @@ class WP_Object_Cache {
if ( $this->_exists( $id, $group ) ) if ( $this->_exists( $id, $group ) )
return false; return false;
return $this->set($key, $data, $group, $expire); return $this->set( $key, $data, $group, (int) $expire );
} }
/** /**
@ -509,7 +509,7 @@ class WP_Object_Cache {
* @param int $expire When to expire the cache contents * @param int $expire When to expire the cache contents
* @return bool False if not exists, true if contents were replaced * @return bool False if not exists, true if contents were replaced
*/ */
function replace( $key, $data, $group = 'default', $expire = '' ) { function replace( $key, $data, $group = 'default', $expire = 0 ) {
if ( empty( $group ) ) if ( empty( $group ) )
$group = 'default'; $group = 'default';
@ -520,7 +520,7 @@ class WP_Object_Cache {
if ( ! $this->_exists( $id, $group ) ) if ( ! $this->_exists( $id, $group ) )
return false; return false;
return $this->set( $key, $data, $group, $expire ); return $this->set( $key, $data, $group, (int) $expire );
} }
/** /**
@ -559,7 +559,7 @@ class WP_Object_Cache {
* @param int $expire Not Used * @param int $expire Not Used
* @return bool Always returns true * @return bool Always returns true
*/ */
function set($key, $data, $group = 'default', $expire = '') { function set( $key, $data, $group = 'default', $expire = 0 ) {
if ( empty( $group ) ) if ( empty( $group ) )
$group = 'default'; $group = 'default';

View File

@ -490,6 +490,7 @@ function get_transient( $transient ) {
*/ */
function set_transient( $transient, $value, $expiration = 0 ) { function set_transient( $transient, $value, $expiration = 0 ) {
$value = apply_filters( 'pre_set_transient_' . $transient, $value ); $value = apply_filters( 'pre_set_transient_' . $transient, $value );
$expiration = (int) $expiration;
if ( wp_using_ext_object_cache() ) { if ( wp_using_ext_object_cache() ) {
$result = wp_cache_set( $transient, $value, 'transient', $expiration ); $result = wp_cache_set( $transient, $value, 'transient', $expiration );
@ -1049,6 +1050,7 @@ function get_site_transient( $transient ) {
*/ */
function set_site_transient( $transient, $value, $expiration = 0 ) { function set_site_transient( $transient, $value, $expiration = 0 ) {
$value = apply_filters( 'pre_set_site_transient_' . $transient, $value ); $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
$expiration = (int) $expiration;
if ( wp_using_ext_object_cache() ) { if ( wp_using_ext_object_cache() ) {
$result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );