SDWebImage / SDWebImageLinkPlugin

A SDWebImage loader plugin, to support load rich link image with LinkPresentation framework
MIT License
17 stars 2 forks source link

Check for cached LPLinkMeta? #18

Open inPhilly opened 3 years ago

inPhilly commented 3 years ago

Is there a way to check if cached LPLinkMetadata exists for a URL? And then, if the LPLinkMetadata does NOT exist in the cache, saving custom LPLinkMetadata to the cache by providing a url, title, and image url?

inPhilly commented 3 years ago

I would like to do this without actually showing any images; i.e. without using UIImageView or LPLinkView. This would be purely backend.

dreampiggy commented 3 years ago

If you don't need any UIImageView/LPLinkView. You can just use SDImageCache to query the cache existence. Just as normal HTTP URL.

After query, you can decode the LPLinkMetadata from the sd_extendedObject of the UIImage, check that object's class and grab back.

If you just want to know whether this is cached or not, just check for that cache key (SDImageCache has API: imageDataExist), don't need to query the image and LPLinkMetadata back.

See: https://github.com/SDWebImage/SDWebImageLinkPlugin/blob/master/SDWebImageLinkPlugin/Classes/LPLinkView%2BWebCache.m#L94

inPhilly commented 3 years ago

How can I query the SDImageCache for cached LPLinkMetaData? I see no methods for that.

How can I cache LPLinkMetaData without instantiating an image?

On Aug 9, 2020, at 3:33 AM, DreamPiggy notifications@github.com wrote:

 If you don't need any UIImageView/LPLinkView. You can just use SDImageCache to query the cache existence.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

dreampiggy commented 3 years ago

The LPLinkMetadata is encoded use keyed-archive and stored into Image Data’s xattr (See: https://en.m.wikipedia.org/wiki/Extended_file_attributes)

You can get the Image Data path by using SDImageCache.cachePathForKey

Then using POSIX API to grab xattr. We have a non-public helper API here, used internally: https://github.com/SDWebImage/SDWebImage/blob/5.8.3/SDWebImage/Private/SDFileAttributeHelper.h

Then using keyed-unarchive to decode into LPLinkMetadata class.