KVLightTasksManager

public class KVLightTasksManager<K, Element> where K : Hashable

A lightweight key-value tasks manager that integrates a cache and configurable providers.

  • Data provider styles for single and batch fetching.

    See more

    Declaration

    Swift

    enum DataProvider
  • Configuration for queue sizing, priority, retries, and cache policy.

    See more

    Declaration

    Swift

    struct Config
  • Callback delivering the result for a single key.

    Declaration

    Swift

    typealias ResultCallback = (K, Result<Element?, Error>) -> Void
  • Callback delivering results for a batch of keys.

    Declaration

    Swift

    typealias BatchResultCallback = ([(K, Result<Element?, Error>)]) -> Void
  • Creates a manager using a prepared configuration.

    Declaration

    Swift

    convenience init(config: Config)
  • Creates a manager from a provider with default configuration values.

    Declaration

    Swift

    convenience init(dataProvider: DataProvider)
  • Initializes using a callback-based single-key provider.

    Declaration

    Swift

    convenience init(_ provide: @escaping DataProvider.Monoprovide)
  • Initializes using an async/await single-key provider.

    Declaration

    Swift

    convenience init(_ provide: @escaping DataProvider.AsyncMonoprovide)
  • Initializes using a synchronous single-key provider.

    Declaration

    Swift

    convenience init(_ provide: @escaping DataProvider.SyncMonoprovide)
  • Initializes using a callback-based multi-key provider with optional batching.

    Declaration

    Swift

    convenience init(maximumBatchCount: UInt = 20, _ provide: @escaping DataProvider.Multiprovide)
  • Initializes using an async/await multi-key provider with optional batching.

    Declaration

    Swift

    convenience init(maximumBatchCount: UInt = 20, _ provide: @escaping DataProvider.AsyncMultiprovide)
  • Initializes using a synchronous multi-key provider with optional batching.

    Declaration

    Swift

    convenience init(maximumBatchCount: UInt = 20, _ provide: @escaping DataProvider.SyncMultiprovide)
  • Errors specific to KVLightTasksManager.

    See more

    Declaration

    Swift

    enum Errors : Error
  • Fetches a single key and returns the result via callback.

    This method automatically handles cache validation and ignores invalid keys as indicated by the cache configuration’s keyValidator. Invalid keys will return nil without triggering any network requests.

    Declaration

    Swift

    func fetch(key: K, completion: @escaping ResultCallback)

    Parameters

    key

    The key to fetch

    completion

    Callback that receives the result for the key

  • Fetches multiple keys and returns results via callback for each key.

    This method automatically handles cache validation and ignores invalid keys as indicated by the cache configuration’s keyValidator. Invalid keys will return nil without triggering any network requests.

    Important: This method guarantees that the completion callback will be called exactly once for each key in the input array, regardless of whether the key is found in cache or requires remote fetching. For example, if you pass 5 keys, the completion callback will be called exactly 5 times, once for each key.

    Declaration

    Swift

    func fetch(keys: [K], completion: @escaping ResultCallback)

    Parameters

    keys

    Array of keys to fetch

    completion

    Callback that receives results for each key (called once per key)

  • Fetches multiple keys and returns results via batch callback.

    This method automatically handles cache validation and ignores invalid keys as indicated by the cache configuration’s keyValidator. Invalid keys will return nil without triggering any network requests.

    Important: This method guarantees that the batch callback will be called exactly once with all results, regardless of whether keys are found in cache or require remote fetching. The callback receives an array of (key, result) tuples.

    Note: Duplicate keys in the input array are handled by deduplication at the unique key level, ensuring each unique key is fetched only once while still providing results for all input keys including duplicates.

    Declaration

    Swift

    func fetch(keys: [K], multiCallback: @escaping BatchResultCallback)

    Parameters

    keys

    Array of keys to fetch (duplicates are allowed)

    multiCallback

    Batch callback that receives all results at once

  • asyncFetch(keys:) Asynchronous

    Fetches multiple keys and returns results asynchronously.

    This method automatically handles cache validation and ignores invalid keys as indicated by the cache configuration’s keyValidator. Invalid keys will return nil without triggering any network requests.

    Important: This method guarantees that results will be returned for each key in the input array, regardless of whether the key is found in cache or requires remote fetching. For example, if you pass 5 keys, you will receive exactly 5 results.

    Note: Duplicate keys in the input array are handled by deduplication at the unique key level, ensuring each unique key is fetched only once while still providing results for all input keys including duplicates.

    This is the async/await version of the batch callback-based fetch(keys:multiCallback:) method. It provides a more modern Swift concurrency interface for batch key fetching.

    Declaration

    Swift

    func asyncFetch(keys: [K]) async -> [(K, Result<Element?, Error>)]

    Parameters

    keys

    Array of keys to fetch (duplicates are allowed)

    Return Value

    Array of tuples containing (key, result) pairs

  • Fetches a single key and returns the result asynchronously.

    This method automatically handles cache validation and ignores invalid keys as indicated by the cache configuration’s keyValidator. Invalid keys will return nil without triggering any network requests.

    This is the async/await version of the callback-based fetch(key:completion:) method. It provides a more modern Swift concurrency interface for single key fetching.

    Throws

    Any error that occurs during the fetch operation

    Declaration

    Swift

    func asyncFetchThrowing(key: K) async throws -> Element?

    Parameters

    key

    The key to fetch

    Return Value

    The fetched element, or nil if not found or invalid

  • asyncFetch(key:) Asynchronous

    Fetches a single key and returns the result asynchronously.

    This method automatically handles cache validation and ignores invalid keys as indicated by the cache configuration’s keyValidator. Invalid keys will return nil without triggering any network requests.

    This is the async/await version of the callback-based fetch(key:completion:) method. It provides a more modern Swift concurrency interface for single key fetching. Unlike asyncFetchThrowing, this method returns a Result type that encapsulates both success and failure cases, allowing for more flexible error handling.

    Declaration

    Swift

    func asyncFetch(key: K) async -> Result<Element?, Error>

    Parameters

    key

    The key to fetch

    Return Value

    A Result containing the fetched element or an error