Skip to content

Instantly share code, notes, and snippets.

@mjhassan
Last active September 3, 2019 04:48
Show Gist options
  • Select an option

  • Save mjhassan/41404ee8d96e5c4aaac9993c0959cc4d to your computer and use it in GitHub Desktop.

Select an option

Save mjhassan/41404ee8d96e5c4aaac9993c0959cc4d to your computer and use it in GitHub Desktop.
Shared url cache configuration
extension URLCache {
static func configSharedCache(directory: String? = Bundle.main.bundleIdentifier, memory: Int = 0, disk: Int = 0) {
URLCache.shared = {
let cacheDirectory = (NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] as String).appendingFormat("/\(directory ?? "cache")/" )
return URLCache(memoryCapacity: memory, diskCapacity: disk, diskPath: cacheDirectory)
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment