Changeset 1187

Show
Ignore:
Timestamp:
01/15/08 11:56:58 (11 months ago)
Author:
donncha
Message:

Fix disk caching: save and gets match, avoid possible collisions between blogs

Files:

Legend:

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

    r1125 r1187  
    140140 
    141141        function get($id, $group = 'default', $count_hits = true) { 
    142                 $hash = $this->key($id, $group); 
     142                if (empty ($group)) 
     143                        $group = 'default'; 
     144 
    143145                $group_key = $this->key( '', $group ); 
    144                 if (empty ($group)) 
    145                         $group = 'default'; 
     146                $hash = $this->key($id, $group_key); 
    146147 
    147148                if (isset ($this->cache[$hash])) { 
     
    169170                } 
    170171 
    171                 $cache_file = $this->cache_dir.$this->get_group_dir($group_key)."/".$this->hash($id).'.php'; 
     172                $cache_file = $this->cache_dir.$this->get_group_dir($group_key)."/".$this->hash($hash).'.php'; 
    172173                if (!file_exists($cache_file)) { 
    173174                        $this->non_existant_objects[$hash] = true; 
     
    286287 
    287288        function set($id, $data, $group = 'default', $expire = '') { 
    288                 $hash = $this->key($id, $group); 
     289                $group_key = $this->key( '', $group ); 
     290                $hash = $this->key($id, $group_key); 
    289291                if (empty ($group)) 
    290292                        $group = 'default'; 
     
    295297                $this->cache[$hash] = $data; 
    296298                unset ($this->non_existant_objects[$hash]); 
    297                 $this->dirty_objects[$this->key( '', $group )][] = $id; 
     299                $this->dirty_objects[$group_key][] = $id; 
    298300 
    299301                return true; 
     
    339341                        $ids = array_unique($ids); 
    340342                        foreach ($ids as $id) { 
    341                                 $cache_file = $group_dir.$this->hash($group.'-'.$id).'.php'; 
     343                                $hash = $this->key($id, $group); 
     344                                $cache_file = $group_dir.$this->hash($hash).'.php'; 
    342345 
    343346                                // Remove the cache file if the key is not set. 
    344                                 if (!isset ($this->cache[$group.'-'.$id])) { 
     347                                if (!isset ($this->cache[$hash])) { 
    345348                                        if (file_exists($cache_file)) 
    346349                                                @ unlink($cache_file); 
     
    349352 
    350353                                $temp_file = tempnam($group_dir, 'tmp'); 
    351                                 $serial = CACHE_SERIAL_HEADER.base64_encode(serialize($this->cache[$group.'-'.$id])).CACHE_SERIAL_FOOTER; 
     354                                $serial = CACHE_SERIAL_HEADER.base64_encode(serialize($this->cache[$hash])).CACHE_SERIAL_FOOTER; 
    352355                                $fd = @fopen($temp_file, 'w'); 
    353356                                if ( false === $fd ) {