title: Using Flask-Cache to cache a lxml.html object
body: <p>I'm attempting to make a Flask web application where you have to request the entirety of a non-local website and I was wondering if it was possible to cache it for the purposes of speeding things up, because the website does not change that often but I still want it to update the cache once a day or so.</p>
  
  <p>Anyway, I looked it up and found Flask-Cache, which seemed to do what I wanted so I made appropriate changes to it, and came up with adding this:</p>
  
  <pre><code>from flask.ext.cache import Cache
  [...]
  cache = Cache()
  [...]
  cache.init_app(app)
  [...]
  @cache.cached(timeout=86400, key_prefix='content')
  def get_content():
      return lxml.html.fromstring(urllib2.urlopen('http://WEBSITE.com').read())
  </code></pre>
  
  <p>and then I make a call from the functions that need the content to proceed like so:</p>
  
  <pre><code>content = get_content()
  </code></pre>
  
  <p>Now I'd expect it to reuse the cached lxml.html object everytime a call is made, but that's not what I'm seeing. The id of the object changes every time a call is made and there's no speed-up at all. So have I misunderstood what Flask-Cache does, or am I doing something wrong here? I've tried using the memoize decorator instead, I've tried decreasing the timeout or removing it all together but nothing seems to be making anything difference.</p>
  
  <p>Thanks.</p>