简体   繁体   English

更改NSURLCache内存和磁盘容量不起作用

[英]Changing NSURLCache memory and disk capacity doesn't work

I'm using a NSURLSession configured to use the shared NSURLCache . 我使用的是NSURLSession配置为使用共享NSURLCache I'm trying to change the size of the cache when the app goes in and out of background. 我正在尝试在应用程序进入和退出后台时更改缓存的大小。 The idea is to reduce both memory and disk capacity when the app enters background and restore the original capacity when the app enters foreground. 这个想法是在应用程序进入后台时减少内存和磁盘容量,并在应用程序进入前台时恢复原始容量。

For both memoryCapacity and diskCapacity properties of NSURLCache the doc says : 对于这两种memoryCapacitydiskCapacity的性质NSURLCache的医生说:

At the time this call is made, the [in-memory|on-disk] cache will truncate its contents to the size given, if necessary. 进行此调用时,如果需要,[磁盘上]缓存将将其内容截断为给定的大小。

However, when I set these properties, the cache size never changes even if I set a value (much) lower than currentMemoryUsage or currentDiskUsage . 但是,当我设置这些属性时,即使我设置的值(远小于currentMemoryUsagecurrentDiskUsage ),缓存大小也不会改变。 Also I can easily verify that the memory used by the app doesn't change, an the size of the disk cache doesn't change either. 另外,我可以轻松地验证应用程序使用的内存没有更改,磁盘缓存的大小也没有更改。

It seems that NSURLCache only use the values set when it is initialized and doesn't take into account subsequent changes. 看来NSURLCache仅在初始化时使用设置的值,而没有考虑后续更改。 Calling the getters for memoryCapacity and diskCapacity does return my new values though. 调用getter以获取memoryCapacitydiskCapacity确实会返回我的新值。

Am I missing something or doing something wrong or is this a bug of NSURLCache ? 我是否缺少某些东西或做错了什么,或者这是NSURLCache的错误?

文档中可能有错误。

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

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