3

Is it necessary to assign diskspace when I use URLCache.share instance? What is the default value that it has?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
iOS Monster
  • 2,099
  • 1
  • 22
  • 49

3 Answers3

2

@ScottZhu's answer in Swift:

URLCache.shared.memoryCapacity
URLCache.shared.diskCapacity
URLCache.shared.currentMemoryUsage
URLCache.shared.currentDiskUsage
Manuel
  • 14,274
  • 6
  • 57
  • 130
1

Here's your default cache size in bytes:

po URLSession.shared.configuration.urlCache?.currentMemoryUsage
- some : 1859

po URLSession.shared.configuration.urlCache?.memoryCapacity
- some : 512000

po URLSession.shared.configuration.urlCache?.diskCapacity
- some : 10000000

po URLSession.shared.configuration.urlCache?.currentDiskUsage
- some : 98408

Different devices might have different cache sizes, but that's the way to check it.

Scott Zhu
  • 8,341
  • 6
  • 31
  • 38
0

Yes, you have to use it.

From Apple Docs:

Applications that do not have special caching requirements or constraints should find the default shared cache instance acceptable. An application with more specific needs can create a custom URLCache object and set it as the shared cache instance using setShared(_:). The application should do so before any calls to this method.

If you don't want to use caching set it explicitly to nil.

URLCache.shared = {
        URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
}()
Maddy
  • 1,660
  • 11
  • 24