SQLite function cache
Project description
No depenencies, no external services functional cache.
Only relies on sqlite3 from the standard python library plus hashlib.sha1 and json.dumps also from standard library.
Note: Most of the limits are due to sqlite. There are other libraries who can relief you from these limits. Also this is probabily not usable as a 'real' cache because there is no 'expiry' option. That is why it is a functional cache:
f(x) => y, where function f always gives output y given input x.
Therefore it is usable for expensive and/or recursive functions.
Example for a recursive factorial function:
from functional_cache import FunctionalCache
f = FunctionalCache("factorial.db")
@f.cache
def factorial(n: int) -> str:
"""factorial function that returns the answer in a string.
This so sqlite can save the large integers.
"""
if n < 2:
return "1"
else:
return str(n*int(factorial(n-1)))
def build_up_factorial(n):
print("This will build a factorial database until {n}!".format(n=n))
for i in range(20, n, 20):
print("now at {i}".format(i=i), end="\r")
factorial(i)
n = 900
build_up_factorial(n)
print("{}! = {}".format(n, factorial(900)))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file FunctionalCache-0.1.tar.gz.
File metadata
- Download URL: FunctionalCache-0.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e1379c4117a0f7ebda2e19e744d9e6eb0ad8e4b056e5fedeb4e2341cf8f0423
|
|
| MD5 |
37fe14f5dbf584da040c2143fda99387
|
|
| BLAKE2b-256 |
47c6b56f0df8cf62d37009b88101a8d3221d49f52eada49ad175b46e6d65c97a
|
File details
Details for the file FunctionalCache-0.1-py3-none-any.whl.
File metadata
- Download URL: FunctionalCache-0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
630042192187b5689f95b9d1730f2cd4aad324cf144181b9bf3a6e2d97ea6a48
|
|
| MD5 |
2271a7ed04a7706440ba14b01167121f
|
|
| BLAKE2b-256 |
3266c6c9ba9fbff653a970d073bf91e6c9ff9ff1e82544222de5fc087e74d42b
|
File details
Details for the file FunctionalCache-0.1-py2.py3-none-any.whl.
File metadata
- Download URL: FunctionalCache-0.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5287c80e733670825f56d255aecff066b25400774492608759dd25e640e4fa06
|
|
| MD5 |
e67cb8dc28a69706344eb47d543ee663
|
|
| BLAKE2b-256 |
20ccf856c15ddfd8de809c926b242a9e330104be9463eb3d51971b4f0d4ee372
|