@@ -19,7 +19,12 @@ typedef void (^PINDiskCacheBlock)(PINDiskCache *cache);
19
19
/* *
20
20
A callback block which provides the cache, key and object as arguments
21
21
*/
22
- typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id <NSCoding > __nullable object, NSURL * __nullable fileURL);
22
+ typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id <NSCoding > __nullable object);
23
+
24
+ /* *
25
+ A callback block which provides the key and fileURL of the object
26
+ */
27
+ typedef void (^PINDiskCacheFileURLBlock)(NSString *key, NSURL * __nullable fileURL);
23
28
24
29
/* *
25
30
A callback block which provides a BOOL value as argument
@@ -227,8 +232,6 @@ typedef void (^PINDiskCacheContainsBlock)(BOOL containsObject);
227
232
Retrieves the object for the specified key. This method returns immediately and executes the passed
228
233
block as soon as the object is available.
229
234
230
- @warning The fileURL is only valid for the duration of this block, do not use it after the block ends.
231
-
232
235
@param key The key associated with the requested object.
233
236
@param block A block to be executed serially when the object is available.
234
237
*/
@@ -241,10 +244,15 @@ typedef void (^PINDiskCacheContainsBlock)(BOOL containsObject);
241
244
@warning Access is protected for the duration of the block, but to maintain safe disk access do not
242
245
access this fileURL after the block has ended.
243
246
247
+ @warning The PINDiskCache lock is held while block is executed. Any synchronous calls to the diskcache
248
+ or a cache which owns the instance of the disk cache are likely to cause a deadlock. This is why the block is
249
+ *not* passed the instance of the disk cache. You should also avoid doing extensive work while this
250
+ lock is held.
251
+
244
252
@param key The key associated with the requested object.
245
253
@param block A block to be executed serially when the file URL is available.
246
254
*/
247
- - (void )fileURLForKey : (nullable NSString *)key block : (nullable PINDiskCacheObjectBlock )block ;
255
+ - (void )fileURLForKey : (NSString *)key block : (nullable PINDiskCacheFileURLBlock )block ;
248
256
249
257
/* *
250
258
Stores an object in the cache for the specified key. This method returns immediately and executes the
@@ -308,8 +316,14 @@ typedef void (^PINDiskCacheContainsBlock)(BOOL containsObject);
308
316
309
317
@param block A block to be executed for every object in the cache.
310
318
@param completionBlock An optional block to be executed after the enumeration is complete.
319
+
320
+ @warning The PINDiskCache lock is held while block is executed. Any synchronous calls to the diskcache
321
+ or a cache which owns the instance of the disk cache are likely to cause a deadlock. This is why the block is
322
+ *not* passed the instance of the disk cache. You should also avoid doing extensive work while this
323
+ lock is held.
324
+
311
325
*/
312
- - (void )enumerateObjectsWithBlock : (PINDiskCacheObjectBlock )block completionBlock : (nullable PINDiskCacheBlock)completionBlock ;
326
+ - (void )enumerateObjectsWithBlock : (PINDiskCacheFileURLBlock )block completionBlock : (nullable PINDiskCacheBlock)completionBlock ;
313
327
314
328
#pragma mark -
315
329
// / @name Synchronous Methods
@@ -404,10 +418,17 @@ typedef void (^PINDiskCacheContainsBlock)(BOOL containsObject);
404
418
read from disk, the `object` parameter of the block will be `nil` but the `fileURL` will be available.
405
419
This method blocks the calling thread until all objects have been enumerated.
406
420
@param block A block to be executed for every object in the cache.
421
+
407
422
@warning Do not call this method within the event blocks (<didRemoveObjectBlock>, etc.)
408
423
Instead use the asynchronous version, <enumerateObjectsWithBlock:completionBlock:>.
424
+
425
+ @warning The PINDiskCache lock is held while block is executed. Any synchronous calls to the diskcache
426
+ or a cache which owns the instance of the disk cache are likely to cause a deadlock. This is why the block is
427
+ *not* passed the instance of the disk cache. You should also avoid doing extensive work while this
428
+ lock is held.
429
+
409
430
*/
410
- - (void )enumerateObjectsWithBlock : (nullable PINDiskCacheObjectBlock )block ;
431
+ - (void )enumerateObjectsWithBlock : (nullable PINDiskCacheFileURLBlock )block ;
411
432
412
433
@end
413
434
0 commit comments