CachingServiceHook

public class CachingServiceHook : ServiceHook

The caching service hook caches a server’s response for requests for a specified time and prevents requests from being sent again if they can be served from the cache. Caching is only performed for GET requests as for all other requests, side-effects on the server are assumed.

  • Initializes a new hook that answers requests from the cache whenever the timestamp that they were added does not exceed the specified time to live.

    Declaration

    Swift

    public init(ttl: TimeInterval = 600)

    Parameters

    ttl

    The number of seconds that a cached value is valid, i.e. can safely be answered from the cache instead of sending it to the server again. Defaults to 10 minutes.

  • Declaration

    Swift

    public func onSchedule<R>(
        _ request: R, _ urlRequest: URLRequest
    ) -> R.Result? where R: Request
  • Declaration

    Swift

    public func onSuccess<R>(
        _ request: R, _ urlRequest: URLRequest, result: R.Result
    ) where R: Request