PipelineStage

public struct PipelineStage

A logical grouping of transformers and a cache.

Why create separate stages?

  • To be able to append, replace, or remove some transformations independently of others, e.g. override the model transform without disabling JSON parsing.
  • To cache entities at any intermediate stage of processing.
  • To maintain multiple caches.

  • See

    Pipeline

    • Appends the given transformer to this stage.

      Declaration

      Swift

      public mutating func add(_ transformer: ResponseTransformer)
    • Appends the given transformer to this stage, applying it only if the server’s Content-type header matches any of the contentTypes. The content type matching applies regardles of whether the response is a success or failure.

      Content type patterns can use * to match subsequences. The wildcard does not cross / or + boundaries. Examples:

      "text/plain"
      "text/​*"
      "application/​*+json"
      

      The pattern does not match MIME parameters, so text/plain matches text/plain; charset=utf-8.

      Declaration

      Swift

      public mutating func add(
              _ transformer: ResponseTransformer,
              contentTypes: [String])
    • Removes all transformers configured for this pipeline stage. Use this to replace defaults or previously configured transformers for specific resources:

      service.configure("/thinger/​*.raw") {
        $0.pipeline[.parsing].removeTransformers()
      }
      

      Declaration

      Swift

      public mutating func removeTransformers()
    • An optional persistent cache for this stage.

      When processing a response, the cache will receive the resulting entity after this stage’s transformers have run.

      When inflating a new resource, Siesta will ask caches if it has any content for the resource, starting with the last cache in the pipeline and working backwards. If there is a cache hit, the resulting entity runs through all the pipeline stages after the one that provided the cache hit.

      Note

      Siesta may ask your cache for content before any load requests run. This means that your observer may initially see an empty resources and then get a newData(Cache) event — even if you never call load().

      Declaration

      Swift

      public mutating func cacheUsing<T>(_ cache: T) where T : EntityCache
    • Removes any caching that had been configured at this stage.

      Declaration

      Swift

      public mutating func doNotCache()