ResourceCacher
public class ResourceCacher<Resource> where Resource : Decodable, Resource : Encodable
A storage to persist a resource and it’s etag, when available.
Resource is stored in the DataStore at the provided fileName, while the etag will be stored at \(fileName)_etag
-
Creates a resource cacher with the specified data store and file name.
Declaration
Swift
public init(dataStore: any DataStore, fileName: String)Parameters
dataStoreThe data store to use for persistence.
fileNameThe file name for storing the resource.
-
Returns the stored resource, if present and successfully decodable.
Declaration
Swift
public func readResource() -> Resource? -
Returns the stored etag, if present.
Declaration
Swift
public func readEtag() -> String? -
Saves the provided resource with the etag, if provided, in a transaction.
Both the resource and the etag will override previous resources stored at the same location. In case of a
niletag any previous etag present will be deleted.Declaration
Swift
public func saveResource(_ resource: Resource, etag: String?) throwsParameters
resourcethe resource to be stored.
etagthe etag to save along with this resource.
View on GitHub