# Installation:
pip install ptcache
# Usage:
## as a decorator for function
### use redis
```python
from ptcache import RedisCache, Cache
cache = Cache(RedisCache(password='***'))
@cache.cached(60*10)
def test(a, b, name='age'):
return {"sum": a+b, "name": name}
@cache.uncache(test, kwarg_names=['name'])
def update_test(a, b, name="age"):
return {"sum": a*b, "name": name}
# computed and stored on cache
test(1, 2)
# update and remove cache for function test
update_test(1, 2)
# remove cache manually
cache.remove_cache(test, 1, 2)
cache.remove_cache(test, 1, 2, name="age")
```
### use python object
```python
from ptcache import SimpleCache, Cache
import json
cache = Cache(SimpleCache(pickle=json)) # use json, default is cPickle
@cache.cached(60*10)
def test(a, b, name='age'):
return {"sum": a+b, "name": name}
@cache.uncache(test, kwarg_names=['name'])
def update_test(a, b, name="age"):
return {"sum": a*b, "name": name}
print(test(1, 2))
print(test(1, 2))
```
## as object
```python
from ptcache import RedisCache, SimpleCache
# use redis
cache = RedisCache(password='***')
cache.set('aaa', {'name':'fang', 'age':10, 'money': 12.03}, 60)
print(cache.exists('aaa'))
print(cache.get('aaa'))
print(cache.ttl('aaa'))
cache.delete('aaa')
print('*' * 10)
# use SimpleCache
cache = SimpleCache(timeout=20, threshold=5)
for x in range(6):
cache.set(x, x)
print(cache.count())
for x in range(6):
print(cache.exists(x))
print(cache.ttl(x))
print(cache.get(x))
cache.delete(x)
print('\n')
```
Changelog
=========
1.0.0
-----
Highlights:
* Init
Metadata
Release files for ptcache 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 | Provenance | Actions |
|---|---|---|---|---|
| ptcache-1.0.0.tar.gz | 4.1 kB | Without provenance | Details for ptcache-1.0.0.tar.gz |
Release files / ptcache-1.0.0.tar.gz
| Download URL | ptcache-1.0.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ffcc7ac58530dd8373391003502fac61fba77772b51bf0764fc83b1ffd0f43b
|
|
BLAKE2b-256 checksum How to use checksums |
9f307f1a65089561964952344e3d28467ece10803f32268e31c8ad908f3cabac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ptcache 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.