gpt4 book ai didi

iOS 视频缓存 - 手动缓存删除

转载 作者:行者123 更新时间:2023-12-01 15:44:25 33 4
gpt4 key购买 nike

我有一个使用 React Native Video with iOS caching 的 React Native 应用程序.我一直在研究 RCTVideoCache.m 内部的一种方法这将手动删除特定缓存键的数据。根据视频库用于缓存的 SPTPersistentCache 的文档,可以通过 locking/unlocking a file 删除数据。和 invoking a wipe或查看SPTPersistentCache.h的源代码后使用名为 removeDataForKeys 的方法.

两种方法我都试过了,但是都不成功。

我的第一次尝试 , 我正在使用 wipeLockedFiles .我创建了一个 deleteFromCache()内部方法RCTVideoCache.m .由于默认情况下我的所有视频文件都已解锁,因此在此方法中,我试图锁定与我的 cacheKey 对应的文件和 invoke a wipe在所有锁定的文件(仅包含我的目标 cacheKey 文件)上,如文档中所示。这个方法看起来像:

- (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);
}

以下导致编译期间出现两个错误:
/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];
~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~

我真的不知道为什么这些选择器在 SPTPersistentCache 中不可见.

我的第二次尝试 , 我正在使用 removeDataForKeys() .同样,我创建了一个 deleteFromCache()内部方法 RCTVideoCache.m看起来像这样:
- (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);
}

在第二种方式中,没有错误,但是, key 的数据永远不会被删除。此外, NSLog s 用于响应输出 null航站楼内。

我 100% 确定 cacheKey我提供给我的 deleteFromCache()方法正确,存在对应的数据。但是,在这两种方法中 NSLog(@"Size = %@", @(self.videoCache.totalUsedSizeInBytes));不会改变,我也可以手动验证文件没有被删除。

我真的被困住了,不知道我在这两种情况下编写的代码有什么问题,以及为什么它们都不起作用。我将不胜感激任何帮助!

最佳答案

您可以删除所有子文件夹的文件(tmp/rct.video.cache) ,迭代每一个:

+ (void)deleteFromCache
{
NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.temporaryCachePath error:NULL];

for (NSString *file in tmpDirectory) {
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", self.temporaryCachePath, file] error:NULL];
}
}

关于iOS 视频缓存 - 手动缓存删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61468773/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com