repoze.lru API

Module: repoze.lru

LRU caching class and decorator

class repoze.lru.LRUCache(size)[source]

Implements a pseudo-LRU algorithm (CLOCK)

The Clock algorithm is not kept strictly to improve performance, e.g. to allow get() and invalidate() to work without acquiring the lock.

clear()[source]

Remove all entries from the cache

get(key, default=None)[source]

Return value for key. If not in cache, return default

put(key, val)[source]

Add key to the cache with value val

invalidate(key)[source]

Remove key from the cache

class repoze.lru.ExpiringLRUCache(size, default_timeout=1152921504606846976L)[source]

Implements a pseudo-LRU algorithm (CLOCK) with expiration times

The Clock algorithm is not kept strictly to improve performance, e.g. to allow get() and invalidate() to work without acquiring the lock.

clear()[source]

Remove all entries from the cache

get(key, default=None)[source]

Return value for key. If not in cache or expired, return default

put(key, val, timeout=None)[source]

Add key to the cache with value val

key will expire in $timeout seconds. If key is already in cache, val and timeout will be updated.

invalidate(key)[source]

Remove key from the cache

class repoze.lru.lru_cache(maxsize, cache=None, timeout=None, ignore_unhashable_args=False)[source]

Decorator for LRU-cached function

timeout parameter specifies after how many seconds a cached entry should be considered invalid.

class repoze.lru.CacheMaker(maxsize=None, timeout=1152921504606846976L)[source]

Generates decorators that can be cleared later

lrucache(name=None, maxsize=None)[source]

Named arguments:

  • name (optional) is a string, and should be unique amongst all caches
  • maxsize (optional) is an int, overriding any default value set by the constructor
clear(*names)[source]

Clear the given cache(s).

If no ‘names’ are passed, clear all caches.