Django cache tools originally developed for Ella CMS. It contains few helpful caching tools (such as cached ForeignKey, functions for caching object/objects, decorator for caching function/method, etc.)
Usage for models
In models.py you can use 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
Usage for caching function
In whatever.py you can use 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'))
Build status
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dj-cache-tools-0.6.3.tar.gz
(5.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dj-cache-tools-0.6.3.tar.gz.
File metadata
- Download URL: dj-cache-tools-0.6.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7974c4a92bfc858db8f066363ce0d43b7a88cf7582627b256f6d1e2177031d9
|
|
| MD5 |
45166d01a6e09f254c500cf400aab5ae
|
|
| BLAKE2b-256 |
8d001429cdc663607a7e69a6be12aa5cc41ef1750e976ceb5c480da14e571e93
|
File details
Details for the file dj_cache_tools-0.6.3-py2.py3-none-any.whl.
File metadata
- Download URL: dj_cache_tools-0.6.3-py2.py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
440fc9459eddf63776f63d104d51740da5d45e6f1e602826f723a181c289ee8a
|
|
| MD5 |
b72cb9621c74b224cb74bb9a174fa677
|
|
| BLAKE2b-256 |
f50a248a75dd58c0455ebd6130624bf21ec04132d5e4c27c6b02e7457829a7f3
|