@@ -169,14 +169,18 @@ private function getMaps(): array
169
169
$ this ->mapInputNameToFactory
170
170
) {
171
171
$ lock = $ this ->lockFactory ->createLock ('buildmap_ ' .$ this ->namespace , 5 );
172
- if ($ lock ->isAcquired ()) {
172
+ if (! $ lock ->acquire ()) {
173
173
// Lock is being held right now. Generation is happening.
174
174
// Let's wait and fetch the result from the cache.
175
175
$ lock ->acquire (true );
176
176
$ lock ->release ();
177
177
return $ this ->getMaps ();
178
178
}
179
- $ this ->lockAndBuildMap ($ lock );
179
+ try {
180
+ $ this ->buildMap ();
181
+ } finally {
182
+ $ lock ->release ();
183
+ }
180
184
// This is a very short lived cache. Useful to avoid overloading a server in case of heavy load.
181
185
// Defaults to 2 seconds.
182
186
$ this ->cache ->set ($ keyClassCache , $ this ->mapClassToTypeArray , $ this ->globTtl );
@@ -222,15 +226,19 @@ private function getMapClassToExtendTypeArray(): array
222
226
$ this ->mapClassToExtendTypeArray = $ this ->cache ->get ($ keyExtendClassCache );
223
227
if ($ this ->mapClassToExtendTypeArray === null ) {
224
228
$ lock = $ this ->lockFactory ->createLock ('buildmapclassextend_ ' .$ this ->namespace , 5 );
225
- if ($ lock ->isAcquired ()) {
229
+ if (! $ lock ->acquire ()) {
226
230
// Lock is being held right now. Generation is happening.
227
231
// Let's wait and fetch the result from the cache.
228
232
$ lock ->acquire (true );
229
233
$ lock ->release ();
230
234
return $ this ->getMapClassToExtendTypeArray ();
231
235
}
232
-
233
- $ this ->buildMapClassToExtendTypeArray ($ lock );
236
+ $ lock ->acquire (true );
237
+ try {
238
+ $ this ->buildMapClassToExtendTypeArray ($ lock );
239
+ } finally {
240
+ $ lock ->release ();
241
+ }
234
242
// This is a very short lived cache. Useful to avoid overloading a server in case of heavy load.
235
243
// Defaults to 2 seconds.
236
244
$ this ->cache ->set ($ keyExtendClassCache , $ this ->mapClassToExtendTypeArray , $ this ->globTtl );
@@ -248,15 +256,19 @@ private function getMapNameToExtendType(RecursiveTypeMapperInterface $recursiveT
248
256
$ this ->mapNameToExtendType = $ this ->cache ->get ($ keyExtendNameCache );
249
257
if ($ this ->mapNameToExtendType === null ) {
250
258
$ lock = $ this ->lockFactory ->createLock ('buildmapnameextend_ ' .$ this ->namespace , 5 );
251
- if ($ lock ->isAcquired ()) {
259
+ if (! $ lock ->acquire ()) {
252
260
// Lock is being held right now. Generation is happening.
253
261
// Let's wait and fetch the result from the cache.
254
262
$ lock ->acquire (true );
255
263
$ lock ->release ();
256
264
return $ this ->getMapNameToExtendType ($ recursiveTypeMapper );
257
265
}
258
-
259
- $ this ->buildMapNameToExtendTypeArray ($ lock , $ recursiveTypeMapper );
266
+ $ lock ->acquire (true );
267
+ try {
268
+ $ this ->buildMapNameToExtendTypeArray ($ recursiveTypeMapper );
269
+ } finally {
270
+ $ lock ->release ();
271
+ }
260
272
// This is a very short lived cache. Useful to avoid overloading a server in case of heavy load.
261
273
// Defaults to 2 seconds.
262
274
$ this ->cache ->set ($ keyExtendNameCache , $ this ->mapNameToExtendType , $ this ->globTtl );
@@ -292,16 +304,6 @@ private function getClassList(): array
292
304
return $ this ->classes ;
293
305
}
294
306
295
- private function lockAndBuildMap (Lock $ lock ): void
296
- {
297
- $ lock ->acquire (true );
298
- try {
299
- $ this ->buildMap ();
300
- } finally {
301
- $ lock ->release ();
302
- }
303
- }
304
-
305
307
private function buildMap (): void
306
308
{
307
309
$ this ->mapClassToTypeArray = [];
@@ -363,21 +365,16 @@ private function buildMapClassToExtendTypeArray(Lock $lock): void
363
365
}
364
366
}
365
367
366
- private function buildMapNameToExtendTypeArray (Lock $ lock , RecursiveTypeMapperInterface $ recursiveTypeMapper ): void
368
+ private function buildMapNameToExtendTypeArray (RecursiveTypeMapperInterface $ recursiveTypeMapper ): void
367
369
{
368
- $ lock ->acquire (true );
369
- try {
370
- $ this ->mapNameToExtendType = [];
371
- $ classes = $ this ->getClassList ();
372
- foreach ($ classes as $ className => $ refClass ) {
373
- $ extendType = $ this ->annotationReader ->getExtendTypeAnnotation ($ refClass );
370
+ $ this ->mapNameToExtendType = [];
371
+ $ classes = $ this ->getClassList ();
372
+ foreach ($ classes as $ className => $ refClass ) {
373
+ $ extendType = $ this ->annotationReader ->getExtendTypeAnnotation ($ refClass );
374
374
375
- if ($ extendType !== null ) {
376
- $ this ->storeExtendTypeMapperByNameInCache ($ className , $ extendType , $ refClass ->getFileName (), $ recursiveTypeMapper );
377
- }
375
+ if ($ extendType !== null ) {
376
+ $ this ->storeExtendTypeMapperByNameInCache ($ className , $ extendType , $ refClass ->getFileName (), $ recursiveTypeMapper );
378
377
}
379
- } finally {
380
- $ lock ->release ();
381
378
}
382
379
}
383
380
0 commit comments