33621.patch

Peter Russ, 2012-02-02 14:21

Download (3.07 KB)

View differences:

Packages/Framework/TYPO3.FLOW3/Classes/Cache/Backend/FileBackend.php (revision )
101 101

  
102 102
		$expiryTime = ($lifetime === NULL) ? 0 : (time() + $lifetime);
103 103
		$metaData = str_pad($expiryTime, self::EXPIRYTIME_LENGTH) . implode(' ', $tags) . str_pad(strlen($data), self::DATASIZE_DIGITS);
104
		$result = file_put_contents($temporaryCacheEntryPathAndFilename, $data . $metaData);
104
/**
105
 * COREPATCH Telekom
106
 * by Peter Russ <peter.russ@telekom.de>
107
 * 02.02.12: fix required du to concurrent processes e.g. ajax requests that impacts each other
108
 *
109
 */
105 110

  
106
		if ($result === FALSE) throw new \TYPO3\FLOW3\Cache\Exception('The temporary cache file "' . $temporaryCacheEntryPathAndFilename . '" could not be written.', 1204026251);
107
		$i = 0;
111
        $breakCounter = 10;
112
        do {
113
            $result = file_put_contents($temporaryCacheEntryPathAndFilename, $data . $metaData, LOCK_EX);
114
            if (!$result) {
115
                usleep(500000); // 500000┬ÁS = 0.5s
116
                $breakCounter--;
117
            }
118
        } while (!$result && $breakCounter > 0);
119

  
120

  
121
		if ($result === FALSE) {
122
            throw new \TYPO3\FLOW3\Cache\Exception(
123
                'The temporary cache file "' . $temporaryCacheEntryPathAndFilename . '" could not be written.',
124
                1204026251
125
            );
126
        }
127

  
128
        if (file_exists($temporaryCacheEntryPathAndFilename)) {
129
            // we ensure that the file isn't renamed already
130
            $breakCounter = 10;
108
		$cacheEntryPathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
131
            $cacheEntryPathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
109
		while (!rename($temporaryCacheEntryPathAndFilename, $cacheEntryPathAndFilename) && $i < 5) {
110
			$i++;
132
            do {
133
                // as file might be locked due to other process this might fail!
134
                $result = rename($temporaryCacheEntryPathAndFilename, $cacheEntryPathAndFilename);
135
                if (!$result) {
136
                    usleep(50000);
137
                    $breakCounter--;
111
		}
138
                }
112
		if ($result === FALSE) throw new \TYPO3\FLOW3\Cache\Exception('The cache file "' . $cacheEntryPathAndFilename . '" could not be written.', 1222361632);
139
            } while (!$result && $breakCounter > 0);
140

  
141
            if ($result === FALSE) {
142
                new \TYPO3\FLOW3\Cache\Exception(
143
                    'The cache file "' . $cacheEntryPathAndFilename . '" could not be written.',
144
                    1222361632
145
                );
113
	}
146
            }
147
        }
148

  
149
/**
150
 * end COREPATCH
151
 */	}
114 152

  
115 153
	/**
116 154
	 * Loads data from a cache file.