1

I'm using a NSURLSession configured to use the shared 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 :

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. 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. Calling the getters for memoryCapacity and diskCapacity does return my new values though.

Am I missing something or doing something wrong or is this a bug of NSURLCache ?

deadbeef
  • 5,409
  • 2
  • 17
  • 47
  • Did You find a solution, because it seems that You are right. I hit the same problem today. – Georgi Boyadzhiev Oct 31 '16 at 12:29
  • @GeorgiBoyadzhiev Sorry, I never did. If I remember correctly I ended up choosing an average value that would work for both... – deadbeef Nov 02 '16 at 19:17
  • My tests show that even, when I initialize a new cache with XX capacity, the cache doesn't comply to the size restriction and gets several times bigger. For example with 32MB disk capacity I get cache with size 130-140 MB, this frustrates me a lot, because I want to be able to manage it properly. Thanks for the fast reply! – Georgi Boyadzhiev Nov 03 '16 at 09:58

1 Answers1

0

Probably an error in the documentation.

dgatwood
  • 10,129
  • 1
  • 28
  • 49