Cache

public class Cache<Key, T> where Key : Hashable, T : CachableCompletable

Is a simple cache that can contain multiple values by unique hashable key. Does not invalidate cached values automatically. Parametrised with Key, T that can be either Future or Channel and Context. That gives an opportunity to make cache that can report of status of completion updateally (e.g. download persentage).

  • Block that resolves miss

    Declaration

    Swift

    public typealias MissHandler = (_ key: Key) throws -> T.CompletingType
  • Designated initializer

    Declaration

    Swift

    public init(executor: Executor = .primary, _ missHandler: @escaping MissHandler)

    Parameters

    executor

    executor to call miss handler o

    missHandler

    block that handles cache misses

  • Convenience initializer

    Declaration

    Swift

    public convenience init<C: ExecutionContext>(
      context: C,
      executor: Executor? = nil,
      _ missHandler: @escaping (_ strongContext: C, _ key: Key) throws -> T.CompletingType)

    Parameters

    context

    context that owns Cache

    executor

    override of ExecutionContexts executor. Keep default value of the argument unless you need to override an executor provided by the context

    missHandler

    block that handles cache misses

    strongContext

    context restored from weak reference

  • Fetches value

    Declaration

    Swift

    public func value(
      forKey key: Key,
      mustStartHandlingMiss: Bool = true,
      mustInvalidateOldValue: Bool = false,
      from originalExecutor: Executor? = nil) -> T.CompletingType

    Parameters

    key

    to fetch value for

    mustStartHandlingMiss

    true if handling miss is allowed. false is useful if you want to use value if there is one and do not want to handle miss.

    mustInvalidateOldValue

    true if previous value may not be used.

    Return Value

    Future of Channel

  • Invalidates cached value for specified key

    Declaration

    Swift

    public func invalidate(valueForKey key: Key)