CachableValue

public class CachableValue<T> where T : CachableCompletable

Is a simple cache that can contain single value. Does not invalidate cached values automatically. Parametrised with Completable 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).

  • a block to call when cache miss happened and resolution is needed

    Declaration

    Swift

    public typealias MissHandler = () throws -> T.CompletingType
  • Designated initializer

    Declaration

    Swift

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

    Parameters

    executor

    executor to call miss handle on

    missHandler

    block that handles cache misses

  • Convenience initializer

    Declaration

    Swift

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

    Parameters

    context

    context that owns CachableValue

    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(
      mustStartHandlingMiss: Bool = true,
      mustInvalidateOldValue: Bool = false,
      from originalExecutor: Executor? = nil
      ) -> T.CompletingType

    Parameters

    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

    Declaration

    Swift

    public func invalidate()