SDWebImageCacheSerializer.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDWebImageCompat.h"
  10. typedef NSData * _Nullable(^SDWebImageCacheSerializerBlock)(UIImage * _Nonnull image, NSData * _Nullable data, NSURL * _Nullable imageURL);
  11. /**
  12. This is the protocol for cache serializer.
  13. We can use a block to specify the cache serializer. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using `@convention(block)` to store a block into context options.
  14. */
  15. @protocol SDWebImageCacheSerializer <NSObject>
  16. /// Provide the image data associated to the image and store to disk cache
  17. /// @param image The loaded image
  18. /// @param data The original loaded image data
  19. /// @param imageURL The image URL
  20. - (nullable NSData *)cacheDataWithImage:(nonnull UIImage *)image originalData:(nullable NSData *)data imageURL:(nullable NSURL *)imageURL;
  21. @end
  22. /**
  23. A cache serializer class with block.
  24. */
  25. @interface SDWebImageCacheSerializer : NSObject <SDWebImageCacheSerializer>
  26. - (nonnull instancetype)initWithBlock:(nonnull SDWebImageCacheSerializerBlock)block;
  27. + (nonnull instancetype)cacheSerializerWithBlock:(nonnull SDWebImageCacheSerializerBlock)block;
  28. @end