Skip to main content

A tiny LRU cache implementation and decorator

Project description

repoze.lru

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.

API

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'

Decorator

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

@lru_cache(500)
def expensive_function(*arg):
    pass

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

repoze.lru

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.

Source Distribution

repoze.lru-0.1.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file repoze.lru-0.1.tar.gz.

File metadata

  • Download URL: repoze.lru-0.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for repoze.lru-0.1.tar.gz
Algorithm Hash digest
SHA256 1a17728e908c5cde6fa3c7ebf073e61523c4848643be467e665e87c9fe5d3eda
MD5 fbbf75032b655a1e520ff0d492d183e5
BLAKE2b-256 d6b22dcad0412dd79e8f2d856570624a78540f0988bd3675315e0ee51b760460

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page