No project description provided
Project description
# red_cache
#### 介绍
基于Redis实现的Python缓存工具
#### 示例
##### 安装方法
```shell
$ pip install red-cache==0.0.4
```
##### 缓存函数执行结果
```python
@redis_cache.pickle_cache(key=lambda v, t: "cache:{}:{}".format(v, t), ex=180)
def hell_world(val: str, times: int):
return val * times
```
##### 保存JSON缓存数据
```python
@redis_cache.json_cache(key=lambda v, t: "cache:{}:{}".format(v, t), ex=180)
def hell_world(val: str, times: int):
return {"val": val, "times": times}
```
##### 缓存的属性
```python
class Demo:
def load_xxx(self):
return
xxx = redis_cache.property(key=lambda: "Demo::xxx", ex=10)(lambda self: self.load_xxx())
```
#### 删除缓存
```python
@redis_cache.remove(lambda o: "auth::user:{}".format(o))
def modify_user(user_id):
# DO MODIFY USER
pass
```
使用返回值
```python
@redis_cache.remove(lambda o: "auth::user:{}".format(o), by_return=True)
def modify_user(user_id):
# DO MODIFY USER
return "*********"
```
使用生成器
```python
@redis_cache.remove(lambda o: "auth::user:{}".format(o), by_return=True)
def modify_users(users):
# modify users
for u in users:
yield u
```
@author:[Memory_Leak](http://vvia.xyz/wjLSh5)
#### 介绍
基于Redis实现的Python缓存工具
#### 示例
##### 安装方法
```shell
$ pip install red-cache==0.0.4
```
##### 缓存函数执行结果
```python
@redis_cache.pickle_cache(key=lambda v, t: "cache:{}:{}".format(v, t), ex=180)
def hell_world(val: str, times: int):
return val * times
```
##### 保存JSON缓存数据
```python
@redis_cache.json_cache(key=lambda v, t: "cache:{}:{}".format(v, t), ex=180)
def hell_world(val: str, times: int):
return {"val": val, "times": times}
```
##### 缓存的属性
```python
class Demo:
def load_xxx(self):
return
xxx = redis_cache.property(key=lambda: "Demo::xxx", ex=10)(lambda self: self.load_xxx())
```
#### 删除缓存
```python
@redis_cache.remove(lambda o: "auth::user:{}".format(o))
def modify_user(user_id):
# DO MODIFY USER
pass
```
使用返回值
```python
@redis_cache.remove(lambda o: "auth::user:{}".format(o), by_return=True)
def modify_user(user_id):
# DO MODIFY USER
return "*********"
```
使用生成器
```python
@redis_cache.remove(lambda o: "auth::user:{}".format(o), by_return=True)
def modify_users(users):
# modify users
for u in users:
yield u
```
@author:[Memory_Leak](http://vvia.xyz/wjLSh5)
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for red_cache-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2e9676b807a4dd562671f1d6e456b541115580edf3dd9728e1f6721f2d864c7 |
|
MD5 | f28e325ec37585ce3142b3acbb9b9b4d |
|
BLAKE2b-256 | 73a8c2dbbfb467d4b7b74eb13a54b04f4b492f0d3eae22d2d8161ebf9ac0d808 |