跳转到主要内容

Django缓存工具最初是为Ella CMS开发的

项目描述

Django缓存工具最初是为Ella CMS开发的。它包含一些有用的缓存工具(例如缓存ForeignKey,缓存对象/对象的函数,缓存函数/方法的装饰器等)

模型使用

在models.py中,您可以使用CachedForeignKey

from __future__ import unicode_literals
from django.db import models
from cache_tools.fields import CachedForeignKey


@python_2_unicode_compatible
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    def __str__(self):
        return self.question_text


@python_2_unicode_compatible
class Choice(models.Model):
    question = CachedForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

    def __str__(self):
        return self.choice_text

缓存函数的使用

在whatever.py中,您可以使用cache_this

from cache_tools.utils import cache_this
from .models import Question


@cache_this(lambda *args, **kwargs: 'my_app_all_questions_cache_key')
def get_all_guestions():
    return list(Question.objects.all().order_by('pk'))

构建状态

主分支:
Travis CI - Distributed build platform for the open source community

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

dj-cache-tools-0.6.3.tar.gz (5.8 kB 查看哈希值)

上传时间 源代码

构建分发

dj_cache_tools-0.6.3-py2.py3-none-any.whl (8.1 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下组织支持