Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Least Recently used Cache (LRU Cache) in Python

Project description

lru_cacher
=========

This is a Least Recently Used (LRU) Cache implementation in Python.

INSTALLATION

To install, simply run
python setup.py install

To run unit tests, run
python setup.py test


EXAMPLE USAGE

>>> from time import sleep
>>>
>>> from lru_cacher import LruCacher
>>>
>>> def slowSqrt(n):
>>> sleep(2)
>>> return n**0.5
>>>
>>> cache = LruCache(max_size=200, plan_b_func=slowSqrt)
>>> #This lookup will be slow
>>> answer, found_in_cache = cache.lookup(49)
>>> print answer, found_in_cache
7.0 False
>>>
>>> #This lookup will be fast
>>> answer, found_in_cache = cache.lookup(49)
>>> print answer, found_in_cache
7.0 True
>>>
>>> #Let's modify the cache
>>> cache.update(49, 'seven')
>>> answer, found_in_cache = cache.lookup(49)
>>> print answer, found_in_cache
seven True

Project details


Release history Release notifications

Download files

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

Files for lru_cacher, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size lru_cacher-1.0.0.macosx-10.5-x86_64.exe (67.0 kB) File type Windows Installer Python version any Upload date Hashes View hashes
Filename, size lru_cacher-1.0.0.tar.gz (2.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page