From 1f38a799081ca8ba1f3ad43dae2b0c6061797d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Kloo=C3=9F?= Date: Fri, 25 Jul 2014 09:14:49 +0200 Subject: [PATCH 1/6] [~FEATURE] added xcache support --- app/code/local/Varien/Autoload.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/code/local/Varien/Autoload.php b/app/code/local/Varien/Autoload.php index 729af41..821c236 100644 --- a/app/code/local/Varien/Autoload.php +++ b/app/code/local/Varien/Autoload.php @@ -16,6 +16,7 @@ class Varien_Autoload static protected $_numberOfFilesAddedToCache = 0; static public $useAPC = NULL; + static public $useXCACHE = NULL; static protected $cacheKey = self::CACHE_KEY_PREFIX; /* Base Path */ @@ -37,7 +38,10 @@ public function __construct() } // Allow APC to be disabled externally by explicitly setting Varien_Autoload::$useAPC = FALSE; - if (self::$useAPC === NULL) { + if (self::$useXCACHE === NULL) { + self::$useXCACHE = extension_loaded('XCache') && ini_get('xcache.cacher'); + } + if (self::$useAPC === NULL && self::$useXCACHE == FALSE) { self::$useAPC = extension_loaded('apc') && ini_get('apc.enabled'); } @@ -171,6 +175,11 @@ static public function loadCacheContent() { if ($value !== FALSE) { self::setCache($value); } + } elseif(self::isXcacheUsed()) { + $value = xcache_isset(self::getCacheKey()) ? xcache_get(self::getCacheKey()) : false; + if ($value !== FALSE) { + self::setCache($value); + } } elseif (file_exists(self::getCacheFilePath())) { self::setCache(unserialize(file_get_contents(self::getCacheFilePath()))); } @@ -232,6 +241,16 @@ public static function isApcUsed() return self::$useAPC; } + /** + * Check if xcache is used + * + * @return bool + */ + public static function isXcacheUsed() + { + return self::$useXCACHE; + } + /** * Get cache key (for apc) * @@ -262,6 +281,10 @@ public function __destruct() if (PHP_SAPI != 'cli') { apc_store(self::getCacheKey(), self::$_cache, 0); } + } elseif(self::isXcacheUsed()) { + if (PHP_SAPI != 'cli') { + xcache_set(self::getCacheKey(), self::$_cache, 0); + } } else { $fileContent = serialize(self::$_cache); $tmpFile = tempnam(sys_get_temp_dir(), 'aoe_classpathcache'); From a5a040282b5c5db4768f35f0fc5e5d829d41715c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Kloo=C3=9F?= Date: Fri, 25 Jul 2014 09:25:17 +0200 Subject: [PATCH 2/6] [~IMPROVMENT] convert TAB to spaces --- .../local/Aoe/ClassPathCache/etc/config.xml | 68 +++++++-------- .../aoe_classpathcache/aoe_classpathcache.xml | 12 ++- app/etc/modules/Aoe_ClassPathCache.xml | 12 +-- shell/aoe_classpathcache.php | 86 +++++++++---------- 4 files changed, 88 insertions(+), 90 deletions(-) diff --git a/app/code/local/Aoe/ClassPathCache/etc/config.xml b/app/code/local/Aoe/ClassPathCache/etc/config.xml index 3caf759..ed2691e 100644 --- a/app/code/local/Aoe/ClassPathCache/etc/config.xml +++ b/app/code/local/Aoe/ClassPathCache/etc/config.xml @@ -1,41 +1,41 @@ - - - 0.4.0 - - + + + 0.4.0 + + - - - - Aoe_ClassPathCache_Helper - - - + + + + Aoe_ClassPathCache_Helper + + + - - - - standard - - Aoe_ClassPathCache - aoeclasspathcache - - - - + + + + standard + + Aoe_ClassPathCache + aoeclasspathcache + + + + - - - - - aoe_classpathcache/aoe_classpathcache.xml - - - - - - + + + + + aoe_classpathcache/aoe_classpathcache.xml + + + + + + \ No newline at end of file diff --git a/app/design/adminhtml/default/default/layout/aoe_classpathcache/aoe_classpathcache.xml b/app/design/adminhtml/default/default/layout/aoe_classpathcache/aoe_classpathcache.xml index 040baeb..bb55044 100644 --- a/app/design/adminhtml/default/default/layout/aoe_classpathcache/aoe_classpathcache.xml +++ b/app/design/adminhtml/default/default/layout/aoe_classpathcache/aoe_classpathcache.xml @@ -1,10 +1,8 @@ - - - - - - - + + + + + \ No newline at end of file diff --git a/app/etc/modules/Aoe_ClassPathCache.xml b/app/etc/modules/Aoe_ClassPathCache.xml index 2b233d3..5fe8a1e 100644 --- a/app/etc/modules/Aoe_ClassPathCache.xml +++ b/app/etc/modules/Aoe_ClassPathCache.xml @@ -1,9 +1,9 @@ - - - true - local - - + + + true + local + + \ No newline at end of file diff --git a/shell/aoe_classpathcache.php b/shell/aoe_classpathcache.php index 3632c57..7faa209 100644 --- a/shell/aoe_classpathcache.php +++ b/shell/aoe_classpathcache.php @@ -36,53 +36,53 @@ public function setRevalidateFlagAction() { } - /** **************************************************************************************************************** - * SHELL DISPATCHER - **************************************************************************************************************** */ + /** **************************************************************************************************************** + * SHELL DISPATCHER + **************************************************************************************************************** */ - /** - * Run script - * - * @return void - */ - public function run() { - $action = $this->getArg('action'); - if (empty($action)) { - echo $this->usageHelp(); - } else { - $actionMethodName = $action.'Action'; - if (method_exists($this, $actionMethodName)) { - $this->$actionMethodName(); - } else { - echo "Action $action not found!\n"; - echo $this->usageHelp(); - exit(1); - } - } - } + /** + * Run script + * + * @return void + */ + public function run() { + $action = $this->getArg('action'); + if (empty($action)) { + echo $this->usageHelp(); + } else { + $actionMethodName = $action.'Action'; + if (method_exists($this, $actionMethodName)) { + $this->$actionMethodName(); + } else { + echo "Action $action not found!\n"; + echo $this->usageHelp(); + exit(1); + } + } + } - /** - * Retrieve Usage Help Message - * - * @return string - */ - public function usageHelp() { - $help = 'Available actions: ' . "\n"; - $methods = get_class_methods($this); - foreach ($methods as $method) { - if (substr($method, -6) == 'Action') { - $help .= ' -action ' . substr($method, 0, -6); - $helpMethod = $method.'Help'; - if (method_exists($this, $helpMethod)) { - $help .= $this->$helpMethod(); - } - $help .= "\n"; - } - } - return $help; - } + /** + * Retrieve Usage Help Message + * + * @return string + */ + public function usageHelp() { + $help = 'Available actions: ' . "\n"; + $methods = get_class_methods($this); + foreach ($methods as $method) { + if (substr($method, -6) == 'Action') { + $help .= ' -action ' . substr($method, 0, -6); + $helpMethod = $method.'Help'; + if (method_exists($this, $helpMethod)) { + $help .= $this->$helpMethod(); + } + $help .= "\n"; + } + } + return $help; + } } From 44b127bb8dc4a9522673511369848de72609bcbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Kloo=C3=9F?= Date: Fri, 25 Jul 2014 09:25:52 +0200 Subject: [PATCH 3/6] [~IMPROVMENT] added Xcache definition in template file --- .../template/aoe_classpathcache/aoe_classpathcache.phtml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml b/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml index d161e62..d1199bd 100644 --- a/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml +++ b/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml @@ -9,7 +9,13 @@ $_helper = $this->helper('aoe_classpathcache'); /* @var $_helper Aoe_ClassPathCa __('Storage:') ?> - __('APC') : Mage::helper('adminhtml')->__('file') ?>, + + __('APC'); ?> + + __('XCache'); ?> + + __('file') ?>, + __('Number of entries:') ?> From d6adee9c79e4e875b59378e7cb0b45ad223e440e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Kloo=C3=9F?= Date: Fri, 25 Jul 2014 09:29:08 +0200 Subject: [PATCH 4/6] [~IMPROVMENT] added Adminhtml controller --- .../local/Aoe/ClassPathCache/Helper/Data.php | 13 +++++ .../controllers/Adminhtml/IndexController.php | 54 +++++++++++++++++++ .../local/Aoe/ClassPathCache/etc/config.xml | 15 +++++- .../aoe_classpathcache.phtml | 2 +- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 app/code/local/Aoe/ClassPathCache/controllers/Adminhtml/IndexController.php diff --git a/app/code/local/Aoe/ClassPathCache/Helper/Data.php b/app/code/local/Aoe/ClassPathCache/Helper/Data.php index e3d61cc..04b76dd 100644 --- a/app/code/local/Aoe/ClassPathCache/Helper/Data.php +++ b/app/code/local/Aoe/ClassPathCache/Helper/Data.php @@ -72,5 +72,18 @@ public function getUrl() )); } + /** + * return in the admin area the url for cleanup + * + * @return string|boolean + */ + public function getAdminUrl() + { + if(Mage::app()->getStore()->isAdmin()) + { + return Mage::helper('adminhtml')->getUrl('adminhtmlcpc/index/clear'); + } + return false; + } } diff --git a/app/code/local/Aoe/ClassPathCache/controllers/Adminhtml/IndexController.php b/app/code/local/Aoe/ClassPathCache/controllers/Adminhtml/IndexController.php new file mode 100644 index 0000000..7059373 --- /dev/null +++ b/app/code/local/Aoe/ClassPathCache/controllers/Adminhtml/IndexController.php @@ -0,0 +1,54 @@ ++_helper()->revalidateCache(); + // check also frontend + $response = file_get_contents($this->_helper()->getUrl()); + if ($response != 'OK') { + $success = false; + } + // set message + if($success) + { + $this->_session()->addSuccess($this->_helper()->__('the classpath cache was cleaned.')); + } else { + $this->_session()->addError($this->_helper()->__('could not clear classpath cache.')); + } + // redirect to referrer + $this->_redirectReferer(); + } + + /** + * class path helper + * + * @return Aoe_ClassPathCache_Helper_Data + */ + protected function _helper() + { + return Mage::helper('aoe_classpathcache'); + } + + /** + * adminhtml session + * + * @return Mage_Adminhtml_Model_Session + */ + protected function _session() + { + return Mage::getSingleton('adminhtml/session'); + } +} \ No newline at end of file diff --git a/app/code/local/Aoe/ClassPathCache/etc/config.xml b/app/code/local/Aoe/ClassPathCache/etc/config.xml index ed2691e..99c73f1 100644 --- a/app/code/local/Aoe/ClassPathCache/etc/config.xml +++ b/app/code/local/Aoe/ClassPathCache/etc/config.xml @@ -36,6 +36,17 @@ - - + + + + + admin + + Aoe_ClassPathCache_Adminhtml + adminhtmlcpc + + + + + \ No newline at end of file diff --git a/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml b/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml index d1199bd..82652d3 100644 --- a/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml +++ b/app/design/adminhtml/default/default/template/aoe_classpathcache/aoe_classpathcache.phtml @@ -5,7 +5,7 @@ $_helper = $this->helper('aoe_classpathcache'); /* @var $_helper Aoe_ClassPathCa
- + __('Storage:') ?> From cfbc8e1d0cacf57c54c1e716ffe2d9255b326416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Kloo=C3=9F?= Date: Fri, 25 Jul 2014 09:33:26 +0200 Subject: [PATCH 5/6] [~IMPROVMENT] added realpath to getFileFromClassName, small performance boost with composer or modman (symlinks) --- app/code/local/Varien/Autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/local/Varien/Autoload.php b/app/code/local/Varien/Autoload.php index 821c236..1489efe 100644 --- a/app/code/local/Varien/Autoload.php +++ b/app/code/local/Varien/Autoload.php @@ -111,7 +111,7 @@ static function getFileFromClassName($className) { $fileName .= str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $className))) . '.php'; - return $fileName; + return realpath($fileName); } /** From a26fbecf89856eea3578f0441a8c001f0e2c79fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Kloo=C3=9F?= Date: Fri, 25 Jul 2014 09:51:13 +0200 Subject: [PATCH 6/6] [~FIXED] realpath --- app/code/local/Varien/Autoload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/local/Varien/Autoload.php b/app/code/local/Varien/Autoload.php index 1489efe..6833c2d 100644 --- a/app/code/local/Varien/Autoload.php +++ b/app/code/local/Varien/Autoload.php @@ -111,7 +111,7 @@ static function getFileFromClassName($className) { $fileName .= str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $className))) . '.php'; - return realpath($fileName); + return $fileName; } /** @@ -225,7 +225,7 @@ static public function searchFullPath($filename) foreach ($paths as $path) { $fullPath = $path . DIRECTORY_SEPARATOR . $filename; if (file_exists($fullPath)) { - return $fullPath; + return realpath($fullPath); } } return false;