   getEmbedHiddenItems:=>
     @embedHiddenItems
 
+  setEmbedCache:(cache)=>
+    @embedCache = cache
+
   setEmbedData:(data)=>
+    isChached = no
+    for embed in @embedCache
+      if data.url is embed.url then isCached = yes
+    unless isCached
+      @embedCache.push data
     @embedData = data
 
   setEmbedURL:(url)=>


  resetEmbedAndHide:=>
    @resetEmbed()
    @embedLinks.clearLinks()
    @hide()

  resetEmbed:=>
    @clearEmbed()
    @setEmbedData {}
    @setEmbedURL ''
    @setEmbedHiddenItems []

      callback no

  embedUrl:(url,options={},callback=noop)=>

    # Checking if we have the URL in cached data before requesting it from embedly

    for embed,i in @embedCache
      # for comparison reasons, both urls have to be sanitized a bit. this could
      # use some more complexity (NEEDS TESTING FOR EDGE CASES)

      # user URL should be checked for domain, since embedly returns
      # urls without www. even if they are requested with www.
      url_ = url.replace /www\./, ""

      # remove trailing slash
      if embed.url? then embedUrl = embed.url.replace /\/$/, ""

      # log embed.url, embedUrl, url, url_, embed.url?.indexOf(url,embed.url?.length-url.length)
      if embed.url? and (embed.url is url or not (embedUrl.indexOf(url_,embedUrl.length-url_.length) is -1))
        @setEmbedData @embedCache[i]
        @setEmbedURL url
        @embedExistingData @embedCache[i], options, callback
        return no

    # else we just request the embed

    @embedLoader.show()
    @$("div.link-embed").addClass "loading"
    @fetchEmbed url, options, (data,embedlyOptions)=>
