HACachesContainer

public class HACachesContainer

Container for caches

You can create your own cache accessible in this container like so:

Create a key to represent your cache:

struct YourValueTypeKey: HACacheKey {
    func create(connection: HAConnection) -> HACache<YourValueType> {
        return HACache(connection: connection, populate: , subscribe: )
    }
}

Add a convenience getter to the container itself:

extension HACachesContainer {
    var yourValueType: HACache<YourValueType> { self[YourValueTypeKey.self] }
}

Then, access it from a connection like connection.caches.yourValueType.

  • Create the caches container

    It is not intended that this is accessible outside of the library itself, since we do not make guarantees around its lifecycle. However, to make it easier to write e.g. a mock connection class, it is made available.

    Declaration

    Swift

    public init(connection: HAConnection)

    Parameters

    connection

    The connection to create using

  • Get a cache by its key

    See also

    HACachesContainer class description for how to use keys to retrieve caches.
    • Subscript: The key to look up

    Declaration

    Swift

    public subscript<KeyType>(key: KeyType.Type) -> HACache<KeyType.Value> where KeyType : HACacheKey { get }

    Return Value

    Either the existing cache for the key, or a new one created on-the-fly if none was available

  • Cache of entity states, see HACachedStates for values.

    Declaration

    Swift

    var states: HACache<HACachedStates> { get }
  • Cache of the current user.

    Declaration

    Swift

    var user: HACache<HAResponseCurrentUser> { get }