File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,13 @@ class Cm_Cache_Backend_Redis extends Zend_Cache_Backend implements Zend_Cache_Ba
111111 */
112112 protected $ _luaMaxCStack = 5000 ;
113113
114+ /**
115+ * If 'retry_reads_on_master' is truthy then reads will be retried against master when slave returns "(nil)" value
116+ *
117+ * @var boolean
118+ */
119+ protected $ _retryReadsOnMaster = false ;
120+
114121 /**
115122 * @var stdClass
116123 */
@@ -339,6 +346,10 @@ public function __construct($options = array())
339346 $ this ->_luaMaxCStack = (int ) $ options ['lua_max_c_stack ' ];
340347 }
341348
349+ if (isset ($ options ['retry_reads_on_master ' ])) {
350+ $ this ->_retryReadsOnMaster = (bool ) $ options ['retry_reads_on_master ' ];
351+ }
352+
342353 if (isset ($ options ['auto_expire_lifetime ' ])) {
343354 $ this ->_autoExpireLifetime = (int ) $ options ['auto_expire_lifetime ' ];
344355 }
@@ -441,6 +452,11 @@ public function load($id, $doNotTestCacheValidity = false)
441452 {
442453 if ($ this ->_slave ) {
443454 $ data = $ this ->_slave ->hGet (self ::PREFIX_KEY .$ id , self ::FIELD_DATA );
455+
456+ // Prevent compounded effect of cache flood on asynchronously replicating master/slave setup
457+ if ($ this ->_retryReadsOnMaster && $ data === false ) {
458+ $ data = $ this ->_redis ->hGet (self ::PREFIX_KEY .$ id , self ::FIELD_DATA );
459+ }
444460 } else {
445461 $ data = $ this ->_redis ->hGet (self ::PREFIX_KEY .$ id , self ::FIELD_DATA );
446462 }
You can’t perform that action at this time.
0 commit comments