repoze.lru 0.6

A tiny LRU cache implementation and decorator
repoze.lru is a LRU (least recently used) cache implementation and decorator. Keys and values that are not used frequently will be evicted from the cache faster than keys and values that are used frequently. It works under Python 2.5, Python 2.6, Python 2.7, and Python 3.2.


Creating an LRUCache object:

from repoze.lru import LRUCache
cache = LRUCache(100) # 100 max length

Retrieving from an LRUCache object:

cache.get('nonexisting', 'foo') # will return 'foo'
cache.get('nonexisting') # will return None
cache.get('existing') # will return the value for existing

Adding to an LRUCache object:

cache.put('key', 'value') # will add the key 'key' with the value 'value'

Clearing an LRUCache:



A lru_cache decorator exists. All values passed to the decorated function must be hashable. It does not support keyword arguments:

from repoze.lru import lru_cache

def expensive_function(*arg):

Each function decorated with the lru_cache decorator uses its own cache related to that function.

last updated on:
July 14th, 2012, 2:45 GMT
license type:
BSD License 
developed by:
Agendaless Consulting
ROOT \ Internet \ HTTP (WWW)
Download Button

In a hurry? Add it to your Download Basket!

user rating



Rate it!
What's New in This Release:
  • Added a 'CacheMaker' helper class: a maker keeps references (by name) to the caches it creates, to permit them to be cleared.
  • Added statistics to each cache, tracking lookups, hits, misses, and evictions.
  • Automated building Sphinx docs and testing example snippets under tox.
  • Added Sphinx documentation.
read full changelog

Add your review!