diff --git a/app/code/community/Varien/Autoload.php b/app/code/community/Varien/Autoload.php index 3b84e4c..f0674d3 100644 --- a/app/code/community/Varien/Autoload.php +++ b/app/code/community/Varien/Autoload.php @@ -178,11 +178,11 @@ public static function loadCacheContent() self::setCache($value); } } elseif (file_exists(self::getCacheFilePath())) { - $cacheFilePath = unserialize(file_get_contents(self::getCacheFilePath())); - // If the file is corrupted, it resets cache - if ($cacheFilePath === false) { + $cacheFilePath = require self::getCacheFilePath(); + if (!is_array($cacheFilePath)) { $cacheFilePath = array(); } + self::setCache($cacheFilePath); } @@ -266,27 +266,61 @@ public static function getCache() return self::$_cache; } + /** + * Save the cache to disk + */ + public function save() + { + if (self::isApcUsed()) { + if (PHP_SAPI != 'cli') { + apc_store(self::getCacheKey(), self::$_cache, 0); + } + } elseif (is_dir_writeable(dirname(self::getCacheFilePath()))) { + $this->_createCacheFile(); + } + } + + /** + * Create the cache file + */ + protected function _createCacheFile() + { + $content = " $filename) { + $content .= "\t'$key' => '$filename',\n"; + } + + $content .= ');'; + + $this->_writeCacheFile($content); + } + + /** + * Write the cache to disk + * + * @param string $content + */ + protected function _writeCacheFile($content) + { + $tmpFile = tempnam(sys_get_temp_dir(), 'aoe_classpathcache'); + if (file_put_contents($tmpFile, $content)) { + if (@rename($tmpFile, self::getCacheFilePath())) { + @chmod(self::getCacheFilePath(), 0664); + } else { + @unlink($tmpFile); + } + } + } + /** * Class destructor */ public function __destruct() { if (self::$_numberOfFilesAddedToCache > 0) { - if (self::isApcUsed()) { - if (PHP_SAPI != 'cli') { - apc_store(self::getCacheKey(), self::$_cache, 0); - } - } elseif (is_dir_writeable(dirname(self::getCacheFilePath()))) { - $fileContent = serialize(self::$_cache); - $tmpFile = tempnam(sys_get_temp_dir(), 'aoe_classpathcache'); - if (file_put_contents($tmpFile, $fileContent)) { - if (@rename($tmpFile, self::getCacheFilePath())) { - @chmod(self::getCacheFilePath(), 0664); - } else { - @unlink($tmpFile); - } - } - } + $this->save(); } } }