CodableCaching
public protocol CodableCaching
Protocol to support Codable protocol with Cache
-
the type of the key by which the caller can retrieve values from the cache
Declaration
Swift
associatedtype KeyType
-
Aggregated value of the cost of the entries in the cache. The concrete behavior is implementation dependent but in general it is the cumulated value of the costs
Declaration
Swift
var costOfEntries: Double { get }
-
The number of entries currently stored in the cache
Declaration
Swift
var numberOfEntries: Int { get }
-
Generic function to get a type specific value from the datacache. The type has to conform to Codable protocol
note: Check Apple documentation for further information about Codable protocol: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types
Declaration
Swift
func get<T>(_ type: T.Type, for key: KeyType) throws -> T? where T : Decodable, T : Encodable
Parameters
type
the Codable type itself. For example: “Data.self”
key
a String which is the key of the value
Return Value
an instance of given type or nil
-
Generic function to insert a type specific value to the datacache. The type has to conform to Codable protocol
note: Check Apple documentation for further information about Codable protocol: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types
Declaration
Swift
func put<T>(_ value: T, for key: KeyType, with cost: Double) throws where T : Decodable, T : Encodable
Parameters
value
the instance which has to be stored
key
a String type, which will be the key in the store
-
Generic function to load a CacheEntry from cache for the provided key and decodes the data
Declaration
Swift
func entry<T>(_ type: T.Type, for key: KeyType) throws -> CacheEntry<T>? where T : Decodable, T : Encodable
Parameters
type
the requested type, which has to conform to Codable protocol
key
a String which identifies the entry in the cache
Return Value
a CacheEntry struct with decoded data
-
Function to remove a type specific value from the datacache
note: Check Apple documentation for further information about Codable protocol: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types
Declaration
Swift
func remove(for key: KeyType)
Parameters
key
the of the datavalue to remove
-
Remove all items from the cache
Declaration
Swift
func removeAllValues()
-
Returns the keys which are currently in the datacache
Declaration
Swift
func keys() throws -> AnySequence<KeyType>
Return Value
a Sequence of Strings containing the existing keys in the cache