This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
SnapCache
Snap-in memory caching for Python, no persistence, just pure function result caching.
Motivation
Python’s built-in functools.lru_cache offers an easy way to cache function results, but it has limitations. For example, attempting to cache complex objects like NumPy arrays results in a TypeError: unhashable type: 'numpy.ndarray'.
SnapCache addresses this issue by offering a similar simple decorator interface while supporting caching for any data structure ✨.
Installation
To install SnapCache, use pip:
pip install snapcache
Usage
Function-level Caching
You can cache function results using the WithCache decorator. Just apply it to any function you want to memoize.
from snapcache import WithCache
@WithCache(maxsize=3)
def add(a, b):
return a + b
# Call the function multiple times
print(add(1, 2)) # First call, result is computed and cached
print(add(1, 2)) # Second call, result is retrieved from cache
Method-level Caching
You can also apply the decorator to class methods:
class Foo:
@WithCache(maxsize=3)
def bar(self, a, b):
return a - b
foo = Foo()
print(foo.bar(10, 5)) # First call, result is computed and cached
print(foo.bar(10, 5)) # Second call, result is retrieved from cache
License
This project is licensed under the MIT License - see the LICENSE file for details.
Release files for snapcache 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| snapcache-1.0.0.tar.gz | 2.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| snapcache-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.0 kB
Release files / snapcache-1.0.0.tar.gz
| Download URL | snapcache-1.0.0.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef48ae47c2c6aa90be8df772d47dc5dd9859892f8873917f09d6223bc6c8edc7
|
|
BLAKE2b-256 checksum How to use checksums |
701e77a4a03c5befb8023b98953ff075b7f2d68234b617c4583d1f41901060bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0
|
Release files / snapcache-1.0.0-py3-none-any.whl
| Download URL | snapcache-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
524aea906b696879a27ccdeea18e7f518cad325ea8a0acfdbb69efd9fce2ec27
|
|
BLAKE2b-256 checksum How to use checksums |
451901ab712570e6cb460e4e349865286c8549758e9908502fadcba30165b588
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0
|