Skip to content

Instantly share code, notes, and snippets.

@fbrnc
Created October 4, 2011 19:12
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbrnc/1262502 to your computer and use it in GitHub Desktop.
Save fbrnc/1262502 to your computer and use it in GitHub Desktop.
Magento priority configuration for TwoLevels cache backend
Index: app/code/core/Mage/Core/Model/Cache.php
===================================================================
--- app/code/core/Mage/Core/Model/Cache.php (revision 124392)
+++ app/code/core/Mage/Core/Model/Cache.php (working copy)
@@ -44,7 +44,7 @@
/**
* Cache frontend API
*
- * @var Zend_Cache_Core
+ * @var Varien_Cache_Core
*/
protected $_frontend = null;
@@ -115,6 +115,9 @@
$this->_frontend = Zend_Cache::factory('Varien_Cache_Core', $backend['type'], $frontend, $backend['options'],
true, true, true
);
+ if (isset($options['default_priority'])) {
+ $this->_frontend->setDefaultPriority($options['default_priority']);
+ }
if (isset($options['request_processors'])) {
$this->_requestProcessors = $options['request_processors'];
@@ -235,7 +238,7 @@
$options['fast_backend_autoload'] = true;
$options['slow_backend_custom_naming'] = true;
$options['slow_backend_autoload'] = true;
-
+
if (isset($cacheOptions['auto_refresh_fast_cache'])) {
$options['auto_refresh_fast_cache'] = (bool)$cacheOptions['auto_refresh_fast_cache'];
} else {
Index: lib/Zend/Cache/Backend/TwoLevels.php
===================================================================
--- lib/Zend/Cache/Backend/TwoLevels.php (revision 124392)
+++ lib/Zend/Cache/Backend/TwoLevels.php (working copy)
@@ -443,7 +443,7 @@
'automatic_cleaning' => $slowBackendCapabilities['automatic_cleaning'],
'tags' => $slowBackendCapabilities['tags'],
'expired_read' => $slowBackendCapabilities['expired_read'],
- 'priority' => $slowBackendCapabilities['priority'],
+ 'priority' => true,
'infinite_lifetime' => $slowBackendCapabilities['infinite_lifetime'],
'get_list' => $slowBackendCapabilities['get_list']
);
Index: lib/Varien/Cache/Core.php
===================================================================
--- lib/Varien/Cache/Core.php (revision 124392)
+++ lib/Varien/Cache/Core.php (working copy)
@@ -26,6 +26,23 @@
class Varien_Cache_Core extends Zend_Cache_Core
{
+
+ /**
+ * @var int default cache priority
+ */
+ protected $defaultPriority = 8;
+
+ /**
+ * Set default priority
+ *
+ * @param int $defaultPriority
+ * @return Varien_Cache_Core
+ */
+ public function setDefaultPriority($defaultPriority) {
+ $this->defaultPriority = $defaultPriority;
+ return $this;
+ }
+
/**
* Make and return a cache id
*
@@ -70,8 +87,11 @@
* @throws Zend_Cache_Exception
* @return boolean True if no problem
*/
- public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
+ public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = NULL)
{
+ if (is_null($priority)) {
+ $priority = $this->defaultPriority;
+ }
$tags = $this->_tags($tags);
return parent::save($data, $id, $tags, $specificLifetime, $priority);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment