Skip to main content

A tiny LRU cache implementation and decorator

Project description


repoze.lru is a LRU (least recently used) cache implementation. Keys and values that are not used frequently will be evicted from the cache faster than keys and values that are used frequently.


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'


A lru_cached 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.


0.1 (unreleaesd)

  • Initial release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for repoze.lru, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size repoze.lru-0.1.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page