repoze.lru

A tiny LRU cache implementation and decorator
Download

repoze.lru Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Agendaless Consulting
  • Publisher web site:
  • http://www.repoze.org

repoze.lru Tags


repoze.lru Description

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.APICreating an LRUCache object:from repoze.lru import LRUCachecache = LRUCache(100) # 100 max lengthRetrieving from an LRUCache object:cache.get('nonexisting', 'foo') # will return 'foo'cache.get('nonexisting') # will return Nonecache.get('existing') # will return the value for existingAdding to an LRUCache object:cache.put('key', 'value') # will add the key 'key' with the value 'value'Clearing an LRUCache:cache.clear()DecoratorA 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@lru_cache(500)def expensive_function(*arg): passEach function decorated with the lru_cache decorator uses its own cache related to that function.Product's homepage


repoze.lru Related Software