lib5c.util.lru_cache module

Module containing a backport of Python 3.3’s least recently used cache decorator.

The original module was downloaded from http://code.activestate.com/recipes/578078/, then modified to support hashing of counts dicts and annotationmaps.

lib5c.util.lru_cache.lru_cache(maxsize=100, typed=False)[source]

Least-recently-used cache decorator.

If maxsize is set to None, the LRU features are disabled and the cache can grow without bound.

If typed is True, arguments of different types will be cached separately. For example, f(3.0) and f(3) will be treated as distinct calls with distinct results.

Arguments to the cached function must be hashable.

View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__.

See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used