Updated the Caching section to the Library page in the Documentation catalog.
This commit is contained in:
@@ -37,6 +37,41 @@ It is also possible to use the `AmiiboService` library with your app in Xcode, t
|
|||||||
|
|
||||||
> important: Swift 5.10 or higher is required in order to compile this library.
|
> important: Swift 5.10 or higher is required in order to compile this library.
|
||||||
|
|
||||||
|
## Caching
|
||||||
|
|
||||||
|
The [Amiibo API](https://www.amiiboapi.org) recommends that consumers who call the API regularly implement caching on their systems. This library does not include a built-in cache, leaving the choice of caching strategy to the consumer. The following examples show two common approaches.
|
||||||
|
|
||||||
|
### URLCache on the transport layer
|
||||||
|
|
||||||
|
Pass a custom `URLSessionTransport` with a cache-configured `URLSession` to ``AmiiboLiveClient``:
|
||||||
|
|
||||||
|
```swift
|
||||||
|
import OpenAPIURLSession
|
||||||
|
|
||||||
|
let configuration = URLSessionConfiguration.default
|
||||||
|
|
||||||
|
configuration.urlCache = URLCache(
|
||||||
|
memoryCapacity: 5_000_000,
|
||||||
|
diskCapacity: 50_000_000
|
||||||
|
)
|
||||||
|
|
||||||
|
let transport = URLSessionTransport(
|
||||||
|
configuration: .init(
|
||||||
|
session: URLSession(configuration: configuration)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
let service = AmiiboService(
|
||||||
|
client: AmiiboLiveClient(transport: transport)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
This leverages HTTP cache headers from the server and persists cached responses to disk.
|
||||||
|
|
||||||
|
### Application-level caching
|
||||||
|
|
||||||
|
Alternatively, cache the results returned by ``AmiiboService`` directly in your application using any storage mechanism that fits your needs, such as an in-memory dictionary, a database, or a file-based store.
|
||||||
|
|
||||||
## Tasks
|
## Tasks
|
||||||
|
|
||||||
This library offers a set of ready-to-use tasks that simplify the interaction with the library, which the developer can use from any `Terminal` application.
|
This library offers a set of ready-to-use tasks that simplify the interaction with the library, which the developer can use from any `Terminal` application.
|
||||||
|
|||||||
Reference in New Issue
Block a user