跳转到主要内容

用于Django函数和方法的一个简单缓存

项目描述

# django-elephant

[![构建状态](https://travis-ci.org/jairhenrique/django-elephant.svg)](https://travis-ci.org/jairhenrique/django-elephant)
[![PyPI版本](https://badge.fury.io/py/django-elephant.svg)](https://badge.fury.io/py/django-elephant)
[![codecov.io](https://codecov.io/github/jairhenrique/django-elephant/coverage.svg?branch=master)](https://codecov.io/github/jairhenrique/django-elephant?branch=master)
[![代码问题](https://www.quantifiedcode.com/api/v1/project/03084631935244baa8335617d6502d11/badge.svg)](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 (5.0 kB 查看散列值)

上传时间

构建分发

django_elephant-1.0.0-py2.py3-none-any.whl (4.8 kB 查看散列值)

上传时间 Python 2 Python 3

由以下支持