Skip to main content

C implementation of Python 3 functools.lru_cache

Project description

C implementation of Python 3 functools.lru_cache. Provides speedup of 10-30x over standard library. Passes test suite from standard library for lru_cache.

Provides 2 Least Recently Used caching function decorators:

clru_cache - built-in (faster)
>>> from fastcache import clru_cache
>>> @clru_cache(maxsize=128,typed=False,state=None)
... def f(a, b):
...     return (a, )+(b, )
...
>>> type(f)
>>> <class '_lrucache.cache'>
lru_cache - python wrapper around clru_cache (slower)
>>> from fastcache import lru_cache
>>> @lru_cache(maxsize=128,typed=False,state=None)
... def f(a, b):
...     return (a, )+(b, )
...
>>> type(f)
>>> <class 'function'>

(c)lru_cache(maxsize=128, typed=False, state=None)

Least-recently-used cache decorator.

If maxsize is set to None, the LRU features are disabled and the cache can grow without bound.

If typed is True, arguments of different types will be cached separately. For example, f(3.0) and f(3) will be treated as distinct calls with distinct results.

If state is a list, the items in the list will be incorporated into argument hash.

Arguments to the cached function must be hashable.

View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__.

See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used

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

fastcache-0.3.2.tar.gz (12.6 kB view details)

Uploaded Source

File details

Details for the file fastcache-0.3.2.tar.gz.

File metadata

  • Download URL: fastcache-0.3.2.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fastcache-0.3.2.tar.gz
Algorithm Hash digest
SHA256 65af50f3f67500399f683d6605c99295b2899c85eefc5577f255f109afd4b11d
MD5 081278ddc573e69cba6346ca33b482a6
BLAKE2b-256 1bff96d0d9a2d497532663e6c474c1e6b85f7ece41bf10f4f4477329d93ac8c5

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