DefaultCacheSerializer

public struct DefaultCacheSerializer : CacheSerializer

Represents a basic and default CacheSerializer used in Kingfisher disk cache system. It could serialize and deserialize images in PNG, JPEG and GIF format. For image other than these formats, a normalized pngRepresentation will be used.

  • The default general cache serializer used across Kingfisher’s cache.

    Declaration

    Swift

    public static let `default`: DefaultCacheSerializer
  • Note

    Only when original contains valid PNG, JPEG and GIF format data, the image will be converted to the corresponding data type. Otherwise, if the original is provided but it is not a valid format, the original data will be used for cache.

    If original is nil, the input image will be encoded as PNG data.

    Declaration

    Swift

    public func data(with image: Image, original: Data?) -> Data?

    Parameters

    image

    The image needed to be serialized.

    original

    The original data which is just downloaded. If the image is retrieved from cache instead of downloaded, it will be nil.

    Return Value

    The data object for storing to disk, or nil when no valid data could be serialized.

  • Gets an image deserialized from provided data.

    Declaration

    Swift

    public func image(with data: Data, options: KingfisherParsedOptionsInfo) -> Image?

    Parameters

    data

    The data from which an image should be deserialized.

    options

    Options for deserialization.

    Return Value

    An image deserialized or nil when no valid image could be deserialized.