Cache

public struct Cache<T: DataConvertible where T.Result == T>

Cache everything which conforms to protocol DataConvertible.

  • Size of disk cache.

    Declaration

    Swift

    public var maxDiskCacheBytes = Constants.DefaultDiskCacheSize
  • Amount of disk cache records.

    Declaration

    Swift

    public var maxDiskCacheRecords = Constants.DefaultDiskCacheRecoreds
  • Max cache size of each record for memory.

    Declaration

    Swift

    public var maxMemoryCacheBytesPerRecord = Constants.DefaultMemoryCacheRecordSize
  • How soon the cache will be expired.

    Declaration

    Swift

    public var maxAge = NSTimeInterval.infinity
  • Disk cache directory.

    Declaration

    Swift

    public lazy var cacheDirectoryPath: String =
  • Init with a cache path.

    Declaration

    Swift

    public init(cacheDirectoryPath: String)

    Parameters

    cacheDirectoryPath

    Cache path.

    Return Value

    Instance of cache.

  • Write to cache, in memory and disk both.

    Declaration

    Swift

    public mutating func write(queryKey: String, value: T?, done: ((Bool) -> Void)? = nil)

    Parameters

    queryKey

    Key.

    value

    Value

    done

    Callback closure.

  • Fetch value from cache. First search in memory cache, if not hit then fetch from disk.

    Declaration

    Swift

    public func fetch(queryKey: String, queryPolicy: CacheQueryPolicy = .Normal, done: (T?) -> Void)

    Parameters

    queryKey

    Key.

    queryPolicy

    Query policy, see CacheQueryPolicy.

    done

    Callback when done.

  • Remove cached value.

    Declaration

    Swift

    public func evictObject(key: String)

    Parameters

    key

    Key.

  • Clear all memory cache.

    Declaration

    Swift

    public func clearMemoryCache()
  • Clear all disk cache.

    Declaration

    Swift

    public func clearDiskCache()