title: Python LRU Cache Decorator Per Instance
body: <p>Using the LRU Cache decorator found here:
  <a href="http://code.activestate.com/recipes/578078-py26-and-py30-backport-of-python-33s-lru-cache/" rel="noreferrer">http://code.activestate.com/recipes/578078-py26-and-py30-backport-of-python-33s-lru-cache/</a></p>
  
  <pre><code>from lru_cache import lru_cache
  class Test:
      @lru_cache(maxsize=16)
      def cached_method(self, x):
           return x + 5
  </code></pre>
  
  <p>I can create a decorated class method with this but it ends up creating a global cache that applies to <strong>all</strong> instances of class Test. However, my intent was to create a per instance cache. So if I were to instantiate 3 Tests, I would have 3 LRU caches rather than 1 LRU cache that for all 3 instances.</p>
  
  <p>The only indication I have that this is happening is when calling the cache_info() on the different class instances decorated methods, they all return the same cache statistics (which is extremely unlikely to occur given they are being interacted with very different arguments):</p>
  
  <pre><code>CacheInfo(hits=8379, misses=759, maxsize=128, currsize=128)
  CacheInfo(hits=8379, misses=759, maxsize=128, currsize=128)
  CacheInfo(hits=8379, misses=759, maxsize=128, currsize=128)
  </code></pre>
  
  <p>Is there a decorator or trick that would allow me to easily cause this decorator to create a cache for each class instance?</p>