From 531b7831b439c26538781ef33aece8ceabeae615 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 23 Mar 2026 00:01:43 +0100 Subject: [PATCH] Updated the Caching section to the Library page in the Documentation catalog. --- .../Catalogs/AmiiboService.docc/Library.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Sources/AmiiboService/Catalogs/AmiiboService.docc/Library.md b/Sources/AmiiboService/Catalogs/AmiiboService.docc/Library.md index 86c34ea..a75736e 100644 --- a/Sources/AmiiboService/Catalogs/AmiiboService.docc/Library.md +++ b/Sources/AmiiboService/Catalogs/AmiiboService.docc/Library.md @@ -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. +## 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 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.