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 9494#pragma mark - Cache
9595// /--------------------------------------
9696
97- - (BFTask<PFVoid> *)clearFileCacheAsync ;
97+ - (BFTask<PFVoid> *)clearFileCacheAsyncForFileWithState : (PFFileState *)fileState ;
98+ - (BFTask<PFVoid> *)clearAllFileCacheAsync ;
9899
99100- (NSString *)cachedFilePathForFileState : (PFFileState *)fileState ;
100101
Original file line number Diff line number Diff line change @@ -259,7 +259,18 @@ - (NSString *)cacheFilesDirectoryPath {
259259 return [self .dataSource.fileManager parseCacheItemPathForPathComponent: PFFileControllerCacheDirectoryName_];
260260}
261261
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 {
263274 return [BFTask taskFromExecutor: [BFExecutor defaultExecutor ] withBlock: ^id {
264275 NSString *path = self.cacheFilesDirectoryPath ;
265276 if ([[NSFileManager defaultManager ] fileExistsAtPath: path]) {
Original file line number Diff line number Diff line change @@ -366,6 +366,24 @@ NS_ASSUME_NONNULL_BEGIN
366366 */
367367- (void )cancel ;
368368
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+
369387@end
370388
371389NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change @@ -217,6 +217,20 @@ - (void)cancel {
217217 }];
218218}
219219
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+
220234// /--------------------------------------
221235#pragma mark - Private
222236// /--------------------------------------
You can’t perform that action at this time.
0 commit comments