def weak_lru_cache(maxsize=100):
 class desc(lazyval, ):
  def __get__(self, instance, owner):
   if (instance is None):
    return self
   try:
    return self._cache[instance]
   except KeyError:
    inst = ref(instance)
    @_weak_lru_cache(maxsize)
    @wraps(self._get)
    def wrapper(*args, **kwargs):
     return self._get(inst(), *args, **kwargs)
    self._cache[instance] = wrapper
    return wrapper
  @_weak_lru_cache(maxsize)
  def __call__(self, *args, **kwargs):
   return self._get(*args, **kwargs)
 return desc

def weak_lru_cache ( maxsize = 100 ) : class desc ( lazyval , ) : def __get__ ( self , instance , owner ) : if ( instance is None ) : return self try : return self . _cache [ instance ] except KeyError : inst = ref ( instance ) @ _weak_lru_cache ( maxsize ) @ wraps ( self . _get ) def wrapper ( * args , ** kwargs ) : return self . _get ( inst ( ) , * args , ** kwargs ) self . _cache [ instance ] = wrapper return wrapper @ _weak_lru_cache ( maxsize ) def __call__ ( self , * args , ** kwargs ) : return self . _get ( * args , ** kwargs ) return desc
weak least-recently-used cache decorator .