Make WordPress Core


Ignore:
Timestamp:
02/12/2010 05:06:43 PM (16 years ago)
Author:
ryan
Message:

Preload commonly loaded site options when running multisite without a persistent cache. Introduce wp_cache_reset() and call it instead of wp_cache_init() when re-initing after the blog ID chanages to avoid throwing out the entire cache. Pass cached site options through the site option filter when fetching.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/cache.php

    r13054 r13066  
    150150 */
    151151function wp_cache_add_global_groups( $groups ) {
    152     // Default cache doesn't persist so nothing to do here.
    153     return;
     152    global $wp_object_cache;
     153
     154    return $wp_object_cache->add_global_groups($groups);
    154155}
    155156
     
    164165    // Default cache doesn't persist so nothing to do here.
    165166    return;
     167}
     168
     169/**
     170 * Reset internal cache keys and structures.  If the cache backend uses global blog or site IDs as part of its cache keys,
     171 * this function instructs the backend to reset those keys and perform any cleanup since blog or site IDs have changed since cache init.
     172 *
     173 * @since 2.6.0
     174 *
     175 * @param string|array $groups A group or an array of groups to add
     176 */
     177function wp_cache_reset() {
     178    global $wp_object_cache;
     179
     180    return $wp_object_cache->reset();
    166181}
    167182
     
    219234     */
    220235    var $cache_misses = 0;
     236
     237    /**
     238     * List of global groups
     239     *
     240     * @var array
     241     * @access protected
     242     * @since 3.0.0
     243     */
     244    var $global_groups = array();
    221245
    222246    /**
     
    235259     * @return bool False if cache ID and group already exists, true on success
    236260     */
    237     function add($id, $data, $group = 'default', $expire = '') {
    238         if (empty ($group))
     261    function add( $id, $data, $group = 'default', $expire = '' ) {
     262        if ( empty ($group) )
    239263            $group = 'default';
    240264
     
    243267
    244268        return $this->set($id, $data, $group, $expire);
     269    }
     270
     271    /**
     272     * Sets the list of global groups.
     273     *
     274     * @since 3.0.0
     275     *
     276     * @param array $groups List of groups that are global.
     277     */
     278    function add_global_groups( $groups ) {
     279        $groups = (array) $groups;
     280
     281        $this->global_groups = array_merge($this->global_groups, $groups);
     282        $this->global_groups = array_unique($this->global_groups);
    245283    }
    246284
     
    309347     */
    310348    function get($id, $group = 'default') {
    311         if (empty ($group))
     349        if ( empty ($group) )
    312350            $group = 'default';
    313351
    314         if (isset ($this->cache[$group][$id])) {
     352        if ( isset ($this->cache[$group][$id]) ) {
    315353            $this->cache_hits += 1;
    316354            if ( is_object($this->cache[$group][$id]) )
     
    344382            $group = 'default';
    345383
    346         if (false === $this->get($id, $group))
     384        if ( false === $this->get($id, $group) )
    347385            return false;
    348386
    349387        return $this->set($id, $data, $group, $expire);
     388    }
     389
     390    /**
     391     * Reset keys
     392     *
     393     * @since 3.0.0
     394     */
     395    function reset() {
     396        // Clear out non-global caches since the blog ID has changed.
     397        foreach ( array_keys($this->cache) as $group ) {
     398            if ( !in_array($group, $this->global_groups) )
     399                unset($this->cache[$group]);
     400        }
    350401    }
    351402
     
    371422     */
    372423    function set($id, $data, $group = 'default', $expire = '') {
    373         if (empty ($group))
     424        if ( empty ($group) )
    374425            $group = 'default';
    375426
    376         if (NULL === $data)
     427        if ( NULL === $data )
    377428            $data = '';
    378429
     
    382433        $this->cache[$group][$id] = $data;
    383434
    384         if(isset($this->non_existent_objects[$group][$id]))
     435        if ( isset($this->non_existent_objects[$group][$id]) )
    385436            unset ($this->non_existent_objects[$group][$id]);
    386437
Note: See TracChangeset for help on using the changeset viewer.