gpt4 book ai didi

ios - removeAllCachedResponses 不能清除sharedURLCache?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:18 24 4
gpt4 key购买 nike

我做了一个按钮来清除我的缓存:

    [[NSURLCache sharedURLCache]removeAllCachedResponses];

完成后,我检查 sharedURLCache 的大小:

NSInteger sizeInteger = [[NSURLCache sharedURLCache] currentDiskUsage];
float sizeInMB = sizeInteger / (1024.0f * 1024.0f);

sizeInMB 为 0.17,有时为 0.13。从不 0.0。为什么 removeAllCachedResponses 不会使 sharedURLCache 为零?

ps: 在 AppDelegate.m 中 didFinishLaunchingWithOptions:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024
diskCapacity:20 * 1024 * 1024
diskPath:nil];

[NSURLCache setSharedURLCache:sharedCache];

最佳答案

在渗透测试(安全测试)期间,我遇到了 iOS 在 cache.db 中缓存 url 请求/响应的问题。

我试过用

URLCache.shared.removeCachedResponse(用于:URLRequest)和URLCache.shared.removeAllCachedResponses()

在收到 API 调用的响应后,上述两个 API 似乎都无法正常工作

然后通过在 AppDelegate 的 didFinishLaunchingWithOptions 中添加以下两行代码使其工作

// first remove all url cache from previous versions of app
URLCache.shared.removeAllCachedResponses()


// As we do not want to cache any request response so
// updated shared instance of url cache with custom url cache where
// memoryCapacity = 0, diskCapacity = 0 and diskPath = nil
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)

关于ios - removeAllCachedResponses 不能清除sharedURLCache?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31803720/

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