Cache
public enum Cache
Get and set structs to the cache directory
-
Get a struct from the cache
Declaration
Swift
public static func get<T: Codable>(key: String, as: T.Type, folder: String? = nil) throws -> T
Parameters
key
The name of the item in the cache
as
The struct to use for decoding
folder
The optional subfolder to store the item
Return Value
decoded cache item
-
Save a struct into the cache
Throws
an error if it can’t be savedDeclaration
Swift
public static func set<T: Codable>(key: String, object: T, folder: String? = nil) throws
Parameters
key
The name for the item in the cache
object
Tthe strucåt to save
folder
The optional subfolder to store the item
-
Delete a struct from the cache
Throws
an error if it can’t be savedDeclaration
Swift
public static func delete(key: String, folder: String? = nil) throws
Parameters
key
The name for the item in the cache
folder
The optional subfolder to store the item
-
Get the path to the cache directory
Declaration
Swift
static private func path(for key: String, folder: String?) throws -> URL
Parameters
key
The name of the cache item
folder
The optional subfolder to store the item
Return Value
A full
URL
to the cache direcory