Make WordPress Core

Ticket #21402: format-cache.diff

File format-cache.diff, 6.5 KB (added by wonderboymusic, 11 years ago)
  • wp-includes/cache.php

     
    2121 * @param int $expire When the cache data should be expired
    2222 * @return unknown
    2323 */
    24 function wp_cache_add($key, $data, $group = '', $expire = 0) {
     24function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
    2525        global $wp_object_cache;
    2626
    27         return $wp_object_cache->add($key, $data, $group, $expire);
     27        return $wp_object_cache->add( $key, $data, $group, $expire );
    2828}
    2929
    3030/**
     
    7272 * @param string $group Where the cache contents are grouped
    7373 * @return bool True on successful removal, false on failure
    7474 */
    75 function wp_cache_delete($key, $group = '') {
     75function wp_cache_delete( $key, $group = '' ) {
    7676        global $wp_object_cache;
    7777
    78         return $wp_object_cache->delete($key, $group);
     78        return $wp_object_cache->delete( $key, $group );
    7979}
    8080
    8181/**
     
    154154 * @param int $expire When to expire the cache contents
    155155 * @return bool False if cache key and group already exist, true on success
    156156 */
    157 function wp_cache_replace($key, $data, $group = '', $expire = 0) {
     157function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
    158158        global $wp_object_cache;
    159159
    160         return $wp_object_cache->replace($key, $data, $group, $expire);
     160        return $wp_object_cache->replace( $key, $data, $group, $expire );
    161161}
    162162
    163163/**
     
    173173 * @param int $expire When to expire the cache contents
    174174 * @return bool False if cache key and group already exist, true on success
    175175 */
    176 function wp_cache_set($key, $data, $group = '', $expire = 0) {
     176function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
    177177        global $wp_object_cache;
    178178
    179         return $wp_object_cache->set($key, $data, $group, $expire);
     179        return $wp_object_cache->set( $key, $data, $group, $expire );
    180180}
    181181
    182182/**
     
    189189function wp_cache_add_global_groups( $groups ) {
    190190        global $wp_object_cache;
    191191
    192         return $wp_object_cache->add_global_groups($groups);
     192        return $wp_object_cache->add_global_groups( $groups );
    193193}
    194194
    195195/**
     
    241241         * @access private
    242242         * @since 2.0.0
    243243         */
    244         var $cache = array ();
     244        var $cache = array();
    245245
    246246        /**
    247247         * The amount of times the cache data was already stored in the cache.
     
    292292                if ( empty( $group ) )
    293293                        $group = 'default';
    294294
    295                 if ( $this->_exists($key, $group) )
     295                if ( $this->_exists( $key, $group ) )
    296296                        return false;
    297297
    298                 return $this->set($key, $data, $group, $expire);
     298                return $this->set( $key, $data, $group, $expire );
    299299        }
    300300
    301301        /**
     
    308308        function add_global_groups( $groups ) {
    309309                $groups = (array) $groups;
    310310
    311                 $this->global_groups = array_merge($this->global_groups, $groups);
    312                 $this->global_groups = array_unique($this->global_groups);
     311                $this->global_groups = array_merge( $this->global_groups, $groups );
     312                $this->global_groups = array_unique( $this->global_groups );
    313313        }
    314314
    315315        /**
     
    357357         *              key in the group
    358358         * @return bool False if the contents weren't deleted and true on success
    359359         */
    360         function delete($key, $group = 'default', $force = false) {
     360        function delete( $key, $group = 'default', $force = false ) {
    361361                if ( empty( $group ) )
    362362                        $group = 'default';
    363363
    364364                if ( ! $force && ! $this->_exists( $key, $group ) )
    365365                        return false;
    366366
    367                 unset( $this->cache[$group][$key] );
     367                unset( $this->cache[ $group ][ $key ] );
    368368                return true;
    369369        }
    370370
     
    376376         * @return bool Always returns true
    377377         */
    378378        function flush() {
    379                 $this->cache = array ();
     379                $this->cache = array();
    380380
    381381                return true;
    382382        }
     
    405405                if ( $this->_exists( $key, $group ) ) {
    406406                        $found = true;
    407407                        $this->cache_hits += 1;
    408                         if ( is_object($this->cache[$group][$key]) )
    409                                 return clone $this->cache[$group][$key];
     408                        if ( is_object( $this->cache[ $group ][ $key ] ) )
     409                                return clone $this->cache[ $group ][ $key ];
    410410                        else
    411                                 return $this->cache[$group][$key];
     411                                return $this->cache[ $group ][ $key ];
    412412                }
    413413
    414414                $found = false;
     
    458458         * @param int $expire When to expire the cache contents
    459459         * @return bool False if not exists, true if contents were replaced
    460460         */
    461         function replace($key, $data, $group = 'default', $expire = '') {
     461        function replace( $key, $data, $group = 'default', $expire = '' ) {
    462462                if ( empty( $group ) )
    463463                        $group = 'default';
    464464
    465465                if ( ! $this->_exists( $key, $group ) )
    466466                        return false;
    467467
    468                 return $this->set($key, $data, $group, $expire);
     468                return $this->set( $key, $data, $group, $expire );
    469469        }
    470470
    471471        /**
     
    475475         */
    476476        function reset() {
    477477                // Clear out non-global caches since the blog ID has changed.
    478                 foreach ( array_keys($this->cache) as $group ) {
    479                         if ( !in_array($group, $this->global_groups) )
    480                                 unset($this->cache[$group]);
     478                foreach ( array_keys( $this->cache ) as $group ) {
     479                        if ( !in_array( $group, $this->global_groups ) )
     480                                unset( $this->cache[ $group ] );
    481481                }
    482482        }
    483483
     
    501501         * @param int $expire Not Used
    502502         * @return bool Always returns true
    503503         */
    504         function set($key, $data, $group = 'default', $expire = '') {
     504        function set( $key, $data, $group = 'default', $expire = '' ) {
    505505                if ( empty( $group ) )
    506506                        $group = 'default';
    507507
    508                 if ( is_object($data) )
     508                if ( is_object( $data ) )
    509509                        $data = clone $data;
    510510
    511                 $this->cache[$group][$key] = $data;
     511                $this->cache[ $group ][ $key ] = $data;
    512512                return true;
    513513        }
    514514
     
    526526                echo "<strong>Cache Misses:</strong> {$this->cache_misses}<br />";
    527527                echo "</p>";
    528528                echo '<ul>';
    529                 foreach ($this->cache as $group => $cache) {
     529                foreach ( $this->cache as $group => $cache ) {
    530530                        echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>';
    531531                }
    532532                echo '</ul>';
     
    542542        protected function _exists( $key, $group ) {
    543543                return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
    544544        }
    545 
    546         /**
    547          * Sets up object properties; PHP 5 style constructor
    548          *
    549          * @since 2.0.8
    550          * @return null|WP_Object_Cache If cache is disabled, returns null.
    551          */
    552         function __construct() {
    553                 /**
    554                  * @todo This should be moved to the PHP4 style constructor, PHP5
    555                  * already calls __destruct()
    556                  */
    557                 register_shutdown_function(array(&$this, "__destruct"));
    558         }
    559 
    560         /**
    561          * Will save the object cache before object is completely destroyed.
    562          *
    563          * Called upon object destruction, which should be when PHP ends.
    564          *
    565          * @since  2.0.8
    566          *
    567          * @return bool True value. Won't be used by PHP
    568          */
    569         function __destruct() {
    570                 return true;
    571         }
    572545}