Hash WP_Theme cache keys to ensure long file paths don't overflow in object backends. see #20103.

git-svn-id: http://svn.automattic.com/wordpress/trunk@20176 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-03-14 22:49:36 +00:00
parent d675c19762
commit 24cbb5d9c6
1 changed files with 12 additions and 3 deletions

View File

@ -128,6 +128,14 @@ final class WP_Theme implements ArrayAccess {
*/
private $textdomain_loaded;
/**
* Stores an md5 hash of the theme root, to function as the cache key.
*
* @access private
* @var string
*/
private $cache_hash;
/**
* Flag for whether the themes cache bucket should be persistently cached.
*
@ -171,6 +179,7 @@ final class WP_Theme implements ArrayAccess {
$this->theme_root = $theme_root;
$this->stylesheet = $theme_dir;
$this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet );
$theme_file = $this->stylesheet . '/style.css';
$cache = $this->cache_get( 'theme' );
@ -440,7 +449,7 @@ final class WP_Theme implements ArrayAccess {
* @return bool Return value from wp_cache_add()
*/
private function cache_add( $key, $data ) {
return wp_cache_add( $key . '-' . $this->theme_root . '/' . $this->stylesheet, $data, 'themes', self::$cache_expiration );
return wp_cache_add( $key . '-' . $this->cache_hash, $data, 'themes', self::$cache_expiration );
}
/**
@ -455,7 +464,7 @@ final class WP_Theme implements ArrayAccess {
* @return mixed Retrieved data
*/
private function cache_get( $key ) {
return wp_cache_get( $key . '-' . $this->theme_root . '/' . $this->stylesheet, 'themes' );
return wp_cache_get( $key . '-' . $this->cache_hash, 'themes' );
}
/**
@ -466,7 +475,7 @@ final class WP_Theme implements ArrayAccess {
*/
public function cache_delete() {
foreach ( array( 'theme', 'screenshot', 'screenshot_count', 'files', 'headers' ) as $key )
wp_cache_delete( $key . '-' . $this->theme_root . '/' . $this->stylesheet, 'themes' );
wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' );
}
/**