@@ -49,9 +49,6 @@ class LockGuardedCacheLoader
49
49
50
50
/**
51
51
* Minimal delay timeout in ms.
52
- * Delay will be applied as rand($minimalDelayTimeout, $delayTimeout)
53
- * in order to desynchronize multiple clients trying
54
- * to acquire the lock for the same resource at the same time
55
52
*
56
53
* @var int
57
54
*/
@@ -112,8 +109,7 @@ public function lockedLoadData(
112
109
}
113
110
114
111
if ($ cachedData === false ) {
115
- $ lookupTimeout = rand ($ this ->minimalDelayTimeout , $ this ->delayTimeout );
116
- usleep ($ lookupTimeout * 1000 );
112
+ usleep ($ this ->getLookupTimeout () * 1000 );
117
113
$ cachedData = $ dataLoader ();
118
114
}
119
115
}
@@ -131,7 +127,7 @@ public function lockedLoadData(
131
127
public function lockedCleanData (string $ lockName , callable $ dataCleaner )
132
128
{
133
129
while ($ this ->locker ->isLocked ($ lockName )) {
134
- usleep ($ this ->delayTimeout * 1000 );
130
+ usleep ($ this ->getLookupTimeout () * 1000 );
135
131
}
136
132
try {
137
133
if ($ this ->locker ->lock ($ lockName , $ this ->lockTimeout / 1000 )) {
@@ -141,4 +137,18 @@ public function lockedCleanData(string $lockName, callable $dataCleaner)
141
137
$ this ->locker ->unlock ($ lockName );
142
138
}
143
139
}
140
+
141
+ /**
142
+ * Delay will be applied as rand($minimalDelayTimeout, $delayTimeout).
143
+ * This helps to desynchronize multiple clients trying
144
+ * to acquire the lock for the same resource at the same time
145
+ *
146
+ * @return int
147
+ */
148
+ private function getLookupTimeout ()
149
+ {
150
+ $ lookupTimeout = rand ($ this ->minimalDelayTimeout , $ this ->delayTimeout );
151
+
152
+ return $ lookupTimeout ;
153
+ }
144
154
}
0 commit comments