KeyedCache

public protocol KeyedCache

A key-value cache.

  • Gets an instance of decodable type D parsed from the value associated with the key

    let res = cache.get("hello", as: String.self).wait()
    print(res) // String?
    

    Declaration

    Swift

    func get<D>(_ key: String, as decodable: D.Type) -> Future<D?> where D : Decodable

    Parameters

    key

    Cache key to access.

    decodable

    Decodable type D to decode.

    Return Value

    A future containing an optional value of D, nil if no value was found.

  • Sets the value to an encodable object at the supplied key.

    try cache.set("world", forKey: "hello").wait()
    

    Declaration

    Swift

    func set<E>(_ key: String, to encodable: E) -> Future<Void> where E : Encodable

    Parameters

    key

    Cache key to set.

    encodable

    An Encodable item to set.

    Return Value

    A future that completes when the action finishes. May also contain an error.

  • Removes the value associated with the key.

    try cache.remove("hello")
    

    Declaration

    Swift

    func remove(_ key: String) -> Future<Void>

    Return Value

    A future that completes when the action finishes. May also contain an error.