SDWebImageLinkPlugin icon indicating copy to clipboard operation
SDWebImageLinkPlugin copied to clipboard

Check for cached LPLinkMeta?

Open inPhilly opened this issue 4 years ago • 4 comments

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 avatar Aug 08 '20 15:08 inPhilly

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

inPhilly avatar Aug 08 '20 16:08 inPhilly

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

dreampiggy avatar Aug 09 '20 07:08 dreampiggy

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 [email protected] 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.

inPhilly avatar Aug 09 '20 12:08 inPhilly

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.

dreampiggy avatar Aug 09 '20 12:08 dreampiggy