https://github.com/duboviy/minicache
:package: Python memory caching utilities
https://github.com/duboviy/minicache
cache caching python utility
Last synced: 10 months ago
JSON representation
:package: Python memory caching utilities
- Host: GitHub
- URL: https://github.com/duboviy/minicache
- Owner: duboviy
- License: mit
- Created: 2016-10-08T15:01:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-04-26T19:46:33.000Z (about 6 years ago)
- Last Synced: 2025-08-27T08:35:38.370Z (10 months ago)
- Topics: cache, caching, python, utility
- Language: Python
- Homepage:
- Size: 104 KB
- Stars: 79
- Watchers: 5
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
minicache
Python memory caching utilities for Python 2 and 3 versions, also PyPy.
by [Eugene Duboviy](https://duboviy.github.io/)
[](https://travis-ci.org/duboviy/minicache) [](https://www.codacy.com/app/dubovoy/minicache?utm_source=github.com&utm_medium=referral&utm_content=duboviy/minicache&utm_campaign=Badge_Grade) [](https://pypi.python.org/pypi/minicache) [](https://landscape.io/github/duboviy/minicache/master) [](https://github.com/duboviy/minicache/) [](https://github.com/duboviy/minicache/pulls) [](https://github.com/duboviy/minicache/)
## Why?
A major problem of [funcy.memoize](http://funcy.readthedocs.org/en/stable/calc.html#memoize) you couldn't test with it because there was no (obvious) way to turn it off.
This project was created to suit the "memoization" needs, with a hook to turn it off (for testing or other purposes).
## Current features
* Simple set and get workflow
* Decorator for "memoization" class methods and functions
* Enabling and disabling functionality (including a context manager)
* No additional packages required to be installed (using only standard python lib)
## Installation
Install from PyPI:
```
pip install minicache
```
Or using alternative command:
```
pip install https://github.com/duboviy/minicache/archive/master.zip
```
Or from source use:
```
python setup.py install
```
## Supported python versions
* 2.7
* 3.3
* 3.4
* 3.5
* PyPy
## PyPI
* [Package](https://pypi.python.org/pypi/minicache)
* [Documentation](https://pythonhosted.org/minicache/)
## Examples
Basic usage
```python
>>> from minicache import cache
>>> cache.has('key')
False
>>> cache.get('key', default='default')
'default'
>>> cache.update('key', 'value')
>>> cache.get('key')
'value'
>>> cache.disable()
>>> cache.get('key')
```
Decorator and context manager
```python
from minicache import cache
import time
@cache.this
def somefunc():
time.sleep(5)
return "this will be cached, and you won't have to wait a second time!"
def test_somefunc():
somefunc()
somefunc()
with cache.temporarily_disabled():
# now we'll have to wait again
somefunc()
```
Decorator for "memoization" class methods:
```python
class Foo(Cacheable):
def __init__(self):
super(Foo, self).__init__()
self._bar = 5
@property
@Cacheable.cached
def m1(self):
print('actual call property...', self._bar)
return self._bar
@Cacheable.cached
def m2(self, a, b, k=4, m=10):
s = a + b + k + m
print('actual call method...', a, b, k, m, s)
return s
@Cacheable.cached
def m3(self, a=3, b=2):
s = a + b
print('actual call method (kwargs only)', a, b, s)
return s
```
... and many other features
## License
**MIT** licensed library. See [LICENSE](LICENSE) for details.
## Contributing
If you have suggestions for improving the minicache, please [open an issue or
pull request on GitHub](https://github.com/duboviy/minicache/).
## Badges
[](https://github.com/duboviy/minicache/)
[](https://github.com/duboviy/minicache/) [](https://github.com/duboviy/minicache/) [](https://github.com/duboviy/minicache/)
[](https://github.com/duboviy/minicache/) [](https://github.com/duboviy/minicache/) [](https://github.com/duboviy/minicache/) [](https://github.com/duboviy/minicache/)
[](https://github.com/ellerbrock/open-source-badge/)
[](https://github.com/duboviy/minicache/)