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'))
构建状态
项目详情
关闭
dj-cache-tools-0.6.3.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d7974c4a92bfc858db8f066363ce0d43b7a88cf7582627b256f6d1e2177031d9 |
|
MD5 | 45166d01a6e09f254c500cf400aab5ae |
|
BLAKE2b-256 | 8d001429cdc663607a7e69a6be12aa5cc41ef1750e976ceb5c480da14e571e93 |
关闭
dj_cache_tools-0.6.3-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 440fc9459eddf63776f63d104d51740da5d45e6f1e602826f723a181c289ee8a |
|
MD5 | b72cb9621c74b224cb74bb9a174fa677 |
|
BLAKE2b-256 | f50a248a75dd58c0455ebd6130624bf21ec04132d5e4c27c6b02e7457829a7f3 |