title: How can I share a cache between Gunicorn workers?
body: <p>I am working on a small service using Gunicorn and Flask (Python 3.6).The pseudocode below shows roughly the behavior I want. There are a lot of serialized <code>foo</code> objects, and I want to hold as many of these in memory as possible and delete them on a LRU basis.</p>
  
  <pre><code>cache = Cache()
  
  @app.route('/')
  def foobar():
      name = request.args['name']
      foo = cache.get(name)
      if foo is None:
          foo = load_foo(name)
          cache.add(foo)
  
      return foo.bar()
  </code></pre>
  
  <p>The problem I am having is I do not know how to share this cache between Gunicorn workers. I'm working with limited memory and don't want to be holding duplicate objects. Certain objects will be used very often and some probably never, so I think it really makes sense to hold them in memory.</p>
  
  <p>This is just something that will only be taking requests from another application (both running on the same server), I just wanted to keep this code separate. Am I going the completely wrong direction by even using Gunicorn in the first place?</p>