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, __version__
>>> __version__
'1.1.0'
>>> @clru_cache(maxsize=325, typed=False)
... def fib(n):
... """Terrible Fibonacci number generator."""
... return n if n < 2 else fib(n-1) + fib(n-2)
...
>>> fib(300)
222232244629420445529739893461909967206666939096499764990979600
>>> fib.cache_info()
CacheInfo(hits=298, misses=301, maxsize=325, currsize=301)
>>> print(fib.__doc__)
Terrible Fibonacci number generator.
>>> fib.cache_clear()
>>> fib.cache_info()
CacheInfo(hits=0, misses=0, maxsize=325, currsize=0)
>>> fib.__wrapped__(300)
222232244629420445529739893461909967206666939096499764990979600
>>> type(fib)
>>> <class 'fastcache.clru_cache'>
lru_cache - python wrapper around clru_cache
>>> from fastcache import lru_cache
>>> @lru_cache(maxsize=128, typed=False)
... def f(a, b):
... pass
...
>>> type(f)
>>> <class 'function'>
(c)lru_cache(maxsize=128, typed=False, state=None, unhashable='error')
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 or dict, the items will be incorporated into the
argument hash.
The result of calling the cached function with unhashable (mutable)
arguments depends on the value of *unhashable*:
If *unhashable* is 'error', a TypeError will be raised.
If *unhashable* is 'warning', a UserWarning will be raised, and
the wrapped function will be called with the supplied arguments.
A miss will be recorded in the cache statistics.
If *unhashable* is 'ignore', the wrapped function will be called
with the supplied arguments. A miss will will be recorded in
the cache statistics.
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
Raw data
{
"_id": null,
"home_page": "https://github.com/pbrady/fastcache",
"name": "fastcache",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Peter Brady",
"author_email": "petertbrady@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5f/a3/b280cba4b4abfe5f5bdc643e6c9d81bf3b9dc2148a11e5df06b6ba85a560/fastcache-1.1.0.tar.gz",
"platform": "",
"description": "C implementation of Python 3 functools.lru_cache. Provides speedup of 10-30x\nover standard library. Passes test suite from standard library for lru_cache.\n\nProvides 2 Least Recently Used caching function decorators:\n\n clru_cache - built-in (faster)\n >>> from fastcache import clru_cache, __version__\n >>> __version__\n '1.1.0'\n >>> @clru_cache(maxsize=325, typed=False)\n ... def fib(n):\n ... \"\"\"Terrible Fibonacci number generator.\"\"\"\n ... return n if n < 2 else fib(n-1) + fib(n-2)\n ...\n >>> fib(300)\n 222232244629420445529739893461909967206666939096499764990979600\n >>> fib.cache_info()\n CacheInfo(hits=298, misses=301, maxsize=325, currsize=301)\n >>> print(fib.__doc__)\n Terrible Fibonacci number generator.\n >>> fib.cache_clear()\n >>> fib.cache_info()\n CacheInfo(hits=0, misses=0, maxsize=325, currsize=0)\n >>> fib.__wrapped__(300)\n 222232244629420445529739893461909967206666939096499764990979600\n >>> type(fib)\n >>> <class 'fastcache.clru_cache'>\n\n lru_cache - python wrapper around clru_cache\n >>> from fastcache import lru_cache\n >>> @lru_cache(maxsize=128, typed=False)\n ... def f(a, b):\n ... pass\n ...\n >>> type(f)\n >>> <class 'function'>\n\n\n (c)lru_cache(maxsize=128, typed=False, state=None, unhashable='error')\n\n Least-recently-used cache decorator.\n\n If *maxsize* is set to None, the LRU features are disabled and the cache\n can grow without bound.\n\n If *typed* is True, arguments of different types will be cached separately.\n For example, f(3.0) and f(3) will be treated as distinct calls with\n distinct results.\n\n If *state* is a list or dict, the items will be incorporated into the\n argument hash.\n\n The result of calling the cached function with unhashable (mutable)\n arguments depends on the value of *unhashable*:\n\n If *unhashable* is 'error', a TypeError will be raised.\n\n If *unhashable* is 'warning', a UserWarning will be raised, and\n the wrapped function will be called with the supplied arguments.\n A miss will be recorded in the cache statistics.\n\n If *unhashable* is 'ignore', the wrapped function will be called\n with the supplied arguments. A miss will will be recorded in\n the cache statistics.\n\n View the cache statistics named tuple (hits, misses, maxsize, currsize)\n with f.cache_info(). Clear the cache and statistics with f.cache_clear().\n Access the underlying function with f.__wrapped__.\n\n See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used",
"bugtrack_url": null,
"license": "MIT",
"summary": "C implementation of Python 3 functools.lru_cache",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/pbrady/fastcache"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5fa3b280cba4b4abfe5f5bdc643e6c9d81bf3b9dc2148a11e5df06b6ba85a560",
"md5": "fff901f2f906d7a32098949fa26204e6",
"sha256": "6de1b16e70335b7bde266707eb401a3aaec220fb66c5d13b02abf0eab8be782b"
},
"downloads": -1,
"filename": "fastcache-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "fff901f2f906d7a32098949fa26204e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 20237,
"upload_time": "2019-04-29T16:35:55",
"upload_time_iso_8601": "2019-04-29T16:35:55.586731Z",
"url": "https://files.pythonhosted.org/packages/5f/a3/b280cba4b4abfe5f5bdc643e6c9d81bf3b9dc2148a11e5df06b6ba85a560/fastcache-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2019-04-29 16:35:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pbrady",
"github_project": "fastcache",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"lcname": "fastcache"
}