用于Django函数和方法的一个简单缓存
项目描述
# django-elephant
[](https://travis-ci.org/jairhenrique/django-elephant)
[](https://badge.fury.io/py/django-elephant)
[](https://codecov.io/github/jairhenrique/django-elephant?branch=master)
[](https://www.quantifiedcode.com/app/project/03084631935244baa8335617d6502d11)
**django-elephant是一个用于缓存Django方法或函数响应的简单包装器**
## 安装
```bash
pip install django-elephant
```
## 使用
#### 基本使用
```python
from elephant import memorize
@memorize()
def foo(bar)
return bar
```
#### 设置缓存配置
```python
from django.core.cache import caches
from elephant import memorize
other_cache = caches['other_cache']
@memorize(
cache=other_cache
)
def foo(bar)
return bar
```
#### 设置缓存超时
```python
from elephant import memorize
@memorize(
timeout=1987
)
def foo(bar)
return bar
```
#### 设置缓存键
```python
from elephant import memorize
def my_custom_key(function, *args, **kwargs)
return '{}.{}'.format(
'elephant_'
function.__name__
)
@memorize(
cache_key=my_custom_key
)
def foo(bar)
return bar
```
## 依赖项
- Django>=1.5
## 贡献
- Fork并提交拉取请求!
[](https://travis-ci.org/jairhenrique/django-elephant)
[](https://badge.fury.io/py/django-elephant)
[](https://codecov.io/github/jairhenrique/django-elephant?branch=master)
[](https://www.quantifiedcode.com/app/project/03084631935244baa8335617d6502d11)
**django-elephant是一个用于缓存Django方法或函数响应的简单包装器**
## 安装
```bash
pip install django-elephant
```
## 使用
#### 基本使用
```python
from elephant import memorize
@memorize()
def foo(bar)
return bar
```
#### 设置缓存配置
```python
from django.core.cache import caches
from elephant import memorize
other_cache = caches['other_cache']
@memorize(
cache=other_cache
)
def foo(bar)
return bar
```
#### 设置缓存超时
```python
from elephant import memorize
@memorize(
timeout=1987
)
def foo(bar)
return bar
```
#### 设置缓存键
```python
from elephant import memorize
def my_custom_key(function, *args, **kwargs)
return '{}.{}'.format(
'elephant_'
function.__name__
)
@memorize(
cache_key=my_custom_key
)
def foo(bar)
return bar
```
## 依赖项
- Django>=1.5
## 贡献
- Fork并提交拉取请求!
项目详情
关闭
django-elephant-1.0.0.tar.gz的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 003c4a5f2660556a417602a93108b5240b2a2b30aa95bcba8c1d081097510a9d |
|
MD5 | 4ad6d5003283c7fd9bf655a927ce6b0b |
|
BLAKE2b-256 | fade899335080c19eaff39722830b1cb061c1e995b965ab13c52dc10b6b6b248 |
关闭
django_elephant-1.0.0-py2.py3-none-any.whl的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 9fb8c7babc19d65b75d884ee8bdfa8871cc64b98c68e15c96ff889ffe193345a |
|
MD5 | 009dd89baaf8dca7aaba907c195308a3 |
|
BLAKE2b-256 | 5d7fc794639e4f5b77d769e48b082f94eb3febead030592db41571df9eff8536 |