<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.2.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 2.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLCache/init(memoryCapacity:diskCapacity:diskPath:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLCache(im)initWithMemoryCapacity:diskCapacity:diskPath:"
  },
  "title" : "init(memoryCapacity:diskCapacity:diskPath:)"
}
-->

# init(memoryCapacity:diskCapacity:diskPath:)

Creates a URL cache object with the specified values.

```
init(memoryCapacity: Int, diskCapacity: Int, diskPath path: String?)
```

## Parameters

`memoryCapacity`

The memory capacity of the cache, in bytes.

`diskCapacity`

The disk capacity of the cache, in bytes.

`path`

In macOS, `path` is the location at which to store the on-disk cache.

    In iOS,     `path`     is the name of a subdirectory of the application’s default cache directory in which to store the on-disk cache (the subdirectory is created if it does not exist).

## Return Value

The initialized cache object.

## Discussion

The returned cache instance is backed by disk, so you have more leeway when choosing the capacity for this kind of cache. A disk cache measured in the tens of megabytes should be acceptable in most cases.

## See Also

[`shared`](/documentation/Foundation/URLCache/shared)

The shared URL cache instance.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)