Skip to main content

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


Download files

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

Source Distribution

lru_cacher-1.0.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lru_cacher-1.0.0.macosx-10.5-x86_64.exe (67.0 kB view details)

Uploaded Source

File details

Details for the file lru_cacher-1.0.0.tar.gz.

File metadata

  • Download URL: lru_cacher-1.0.0.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lru_cacher-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ffbd9ef559e79838472824db5226ef3fd68eb79eb5d506a349cbaaab189a74f2
MD5 90db0315ca6d1adb9fb2c2e54064c158
BLAKE2b-256 70333ef83a8d5343635864f82b3a9d36618681925686189b85e2f2a27a7d5cfd

See more details on using hashes here.

File details

Details for the file lru_cacher-1.0.0.macosx-10.5-x86_64.exe.

File metadata

File hashes

Hashes for lru_cacher-1.0.0.macosx-10.5-x86_64.exe
Algorithm Hash digest
SHA256 b7a6fd2cb8b6227574b72f0d28e395c66864a3a24a69dec2d47731f321a43403
MD5 c40d32639591d8951b7015b617f0c6a3
BLAKE2b-256 1bf83afca71abc11892bc9972c6714c153bf1b4a4bafbc352e072c7d6a1a24c7

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