LeonardoCardoso / SwiftLinkPreview

It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
https://leocardz.com/swift-link-preview-5a9860c7756f
MIT License
1.37k stars 197 forks source link

SwiftLinkPreview Never loads response from cache, am i doing it wrong? #146

Closed ShailendraKushwaha closed 3 years ago

ShailendraKushwaha commented 3 years ago
let slp = SwiftLinkPreview(cache: InMemoryCache())

        if let cached = slp.cache.slp_getCachedResponse(url: text) {

           success(cached)
        } else {
            // Perform preview otherwise
            slp.preview(text, onSuccess: {response in
                success(response)
            }
            , onError: {error in
    //            print(error.localizedDescription)
            })
        }

it always have to fetch response from online.

LeonardoCardoso commented 3 years ago

You should use url as the cached key.

if let url = self.slp.extractURL(text: textFieldText),
let cached = self.slp.cache.slp_getCachedResponse(url: url.absoluteString) { }