简体   繁体   English

如何在cordova ios应用程序中禁用NSURL缓存?

[英]how can I disable NSURL cache in cordova ios app?

I'm developing a cordova 4 ios app. 我正在开发一个cordova 4 ios应用程序。 After a security scan, it was recommended that I should disable NSURL caching in order to avoid the creation of the Cache.db file on the devices. 在安全扫描之后,建议我应该禁用NSURL缓存,以避免在设备上创建Cache.db文件。

Is there a way to achieve this? 有没有办法实现这个目标? I've tried this plugin https://github.com/wongatech/cordova-disable-nsurl-cache but it is not working (it says that it works for cordova 3.7). 我已经尝试过这个插件https://github.com/wongatech/cordova-disable-nsurl-cache但它没有用(它说它适用于cordova 3.7)。

Is it a wise thing to completely avoid this NSURL caching or should it be performed just for some request, lets say, the ones with 'sensitive' data? 完全避免这种NSURL缓存是否是明智的事情,还是仅仅针对某些请求执行它,比如那些具有“敏感”数据的请求?

Help anyone? 帮助任何人?

I don't know anything about Cordova, but assuming it uses NSURLConnection or NSURLSession under the hood, and assuming it is possible to add native code, you can disable NSURLConnection caching like this: 我对Cordova一无所知,但假设它使用了NSURLConnection或NSURLSession,并假设可以添加本机代码,则可以禁用NSURLConnection缓存,如下所示:

NSURLCache *URLCache =
    [[NSURLCache alloc] initWithMemoryCapacity:4194304 // 4 MB
                                  diskCapacity:0
                                      diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];

For NSURLSession, you would need to change the session configuration's URLCache property to the URL cache object you created (instead of doing the second line above). 对于NSURLSession,您需要将会话配置的URLCache属性更改为您创建的URL缓存对象(而不是执行上面的第二行)。 That would presumably require changes to Cordova itself if it uses NSURLSession. 如果它使用NSURLSession,那么可能需要更改Cordova本身。

With that said, I have no idea whether that will work or not with Cordova. 话虽如此,我不知道这对Cordova是否有效。 They might use their own networking code instead, in which case you'd have to disable caching in some manner specific to Cordova. 他们可能会使用自己的网络代码,在这种情况下,您必须以某种特定于Cordova的方式禁用缓存。

As for the avoiding URL caching question, again assuming it is using NSURLConnection or NSURLSession, the easiest way to avoid caching anything sensitive is to always use POST requests for sending sensitive data, because those results are never cached. 至于避免URL缓存问题,再次假设它正在使用NSURLConnection或NSURLSession,避免缓存任何敏感的最简单方法是始终使用POST请求来发送敏感数据,因为这些结果永远不会被缓存。

For that matter, even if Cordova uses its own networking code, non-cachability of POST requests should be enforced by pretty much any standards-compliant web cache, so that's probably a fairly safe bet. 就此而言,即使Cordova使用自己的网络代码,POST请求的不可提供性也应该由几乎任何符合标准的Web缓存强制执行,因此这可能是一个相当安全的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM