I have a React Native application which uses React Native Video with iOS caching. I have been working on a method inside RCTVideoCache.m which would manually delete the data of a particular cache key. According to the documentation of SPTPersistentCache, which the video library uses for caching, data can be deleted either by locking/unlocking a file and invoking a wipe or after inspecting the source code of SPTPersistentCache.h
with a method named removeDataForKeys.
I have tried both ways, however, unsuccessfully.
In my first try, I am using wipeLockedFiles. I have created a deleteFromCache()
method inside RCTVideoCache.m. Since all my video files are unlocked by default, in this method I am trying to lock the file corresponding to my cacheKey
and invoke a wipe on all locked files (which would consist of only my target cacheKey
file) as it is demonstrated in the documentation. This method looks like:
- (void)deleteFromCache:(NSString *)cacheKey withCallback:(void(^)(BOOL))handler;{ [self.videoCache lockDataForKeys:@[cacheKey] callback:nil queue:nil]; [self.videoCache wipeLockedFiles]; NSLog(@"Size = %@", @(self.videoCache.totalUsedSizeInBytes)); handler(YES);}
The following results in two errors during compilation:
/Users/.../MyApp/node_modules/react-native-video/ios/VideoCaching/RCTVideoCache.m:79:20: error: no visible @interface for 'SPTPersistentCache' declares the selector 'lockDataForKeys:callback:queue:' [self.videoCache lockDataForKeys:@[cacheKey] callback:nil queue:nil]; ~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/Users/.../MyApp/node_modules/react-native-video/ios/VideoCaching/RCTVideoCache.m:80:20: error: no visible @interface for 'SPTPersistentCache' declares the selector 'wipeLockedFiles' [self.videoCache wipeLockedFiles]; ~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~
I really have no idea why these selectors are not visible from SPTPersistentCache
.
In my second try, I am using removeDataForKeys(). Again, I have created a deleteFromCache()
method inside RCTVideoCache.m which looks like this:
- (void)deleteFromCache:(NSString *)cacheKey withCallback:(void(^)(BOOL))handler;{ [self.videoCache removeDataForKeys:@[cacheKey] callback:^(SPTPersistentCacheResponse * _Nonnull response) { NSLog(@"Result output: %@", response.output); NSLog(@"Error output: %@", [response.error localizedDescription]); } onQueue:dispatch_get_main_queue()]; NSLog(@"Size = %@", @(self.videoCache.totalUsedSizeInBytes)); handler(YES);}
In this second way, there are no errors, however, the data of the key is never deleted. Also, both NSLog
s for the response output null
inside the terminal.
I am 100% sure that the cacheKey
I am providing to my deleteFromCache()
method is correct and data corresponding to it exists. However, in both methods NSLog(@"Size = %@", @(self.videoCache.totalUsedSizeInBytes));
does not change and I can also manually verify that the file has not been deleted.
I am really stuck and do not know what is wrong with the code I've written in both cases and why neither of them works. I would appreciate any help on this!