File tree Expand file tree Collapse file tree 4 files changed +46
-2
lines changed Expand file tree Collapse file tree 4 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 94
94
#pragma mark - Cache
95
95
// /--------------------------------------
96
96
97
- - (BFTask<PFVoid> *)clearFileCacheAsync ;
97
+ - (BFTask<PFVoid> *)clearFileCacheAsyncForFileWithState : (PFFileState *)fileState ;
98
+ - (BFTask<PFVoid> *)clearAllFileCacheAsync ;
98
99
99
100
- (NSString *)cachedFilePathForFileState : (PFFileState *)fileState ;
100
101
Original file line number Diff line number Diff line change @@ -259,7 +259,18 @@ - (NSString *)cacheFilesDirectoryPath {
259
259
return [self .dataSource.fileManager parseCacheItemPathForPathComponent: PFFileControllerCacheDirectoryName_];
260
260
}
261
261
262
- - (BFTask<PFVoid> *)clearFileCacheAsync {
262
+ - (BFTask<PFVoid> *)clearFileCacheAsyncForFileWithState : (PFFileState *)fileState {
263
+ return [BFTask taskFromExecutor: [BFExecutor defaultExecutor ] withBlock: ^id {
264
+ NSString *filePath = [self cachedFilePathForFileState: fileState];
265
+ if (!filePath) {
266
+ return nil ;
267
+ }
268
+ // No need to lock on this, since we are removing from a cache directory.
269
+ return [PFFileManager removeItemAtPathAsync: filePath withFileLock: NO ];
270
+ }];
271
+ }
272
+
273
+ - (BFTask<PFVoid> *)clearAllFileCacheAsync {
263
274
return [BFTask taskFromExecutor: [BFExecutor defaultExecutor ] withBlock: ^id {
264
275
NSString *path = self.cacheFilesDirectoryPath ;
265
276
if ([[NSFileManager defaultManager ] fileExistsAtPath: path]) {
Original file line number Diff line number Diff line change @@ -366,6 +366,24 @@ NS_ASSUME_NONNULL_BEGIN
366
366
*/
367
367
- (void )cancel ;
368
368
369
+ // /--------------------------------------
370
+ #pragma mark - Cache
371
+ // /--------------------------------------
372
+
373
+ /* *
374
+ Clears all cached data for this file.
375
+
376
+ @return The task, with the result set to `nil` if the operation succeeds.
377
+ */
378
+ - (BFTask *)clearCachedDataInBackground ;
379
+
380
+ /* *
381
+ Clears all cached data for all downloaded files.
382
+
383
+ @return The task, with the result set to `nil` if the operation succeeds.
384
+ */
385
+ + (BFTask *)clearAllCachedDataInBackground ;
386
+
369
387
@end
370
388
371
389
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change @@ -217,6 +217,20 @@ - (void)cancel {
217
217
}];
218
218
}
219
219
220
+ #pragma mark Cache
221
+
222
+ - (BFTask *)clearCachedDataInBackground {
223
+ @weakify (self);
224
+ return [self .taskQueue enqueue: ^id (BFTask *_) {
225
+ @strongify (self);
226
+ return [[[[self class ] fileController ] clearFileCacheAsyncForFileWithState: self .state] continueWithSuccessResult: nil ];
227
+ }];
228
+ }
229
+
230
+ + (BFTask *)clearAllCachedDataInBackground {
231
+ return [[[self fileController ] clearAllFileCacheAsync ] continueWithSuccessResult: nil ];
232
+ }
233
+
220
234
// /--------------------------------------
221
235
#pragma mark - Private
222
236
// /--------------------------------------
You can’t perform that action at this time.
0 commit comments