Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 52 additions & 18 deletions app/code/community/Varien/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 = "<?php\n// DO NOT EDIT THIS FILE!\n\nreturn array(\n";

Mage::log(print_r(self::$_cache, true));
foreach (self::$_cache as $key => $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();
}
}
}