Skip to main content

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

Master branch:
Travis CI - Distributed build platform for the open source community

Metadata

Release files for dj-cache-tools 0.6.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-cache-tools 0.6.3
File Size Uploaded
dj-cache-tools-0.6.3.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-cache-tools 0.6.3
File Interpreter ABI Platform
dj_cache_tools-0.6.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 13.8 kB

Release files / dj-cache-tools-0.6.3.tar.gz

Download URL dj-cache-tools-0.6.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d7974c4a92bfc858db8f066363ce0d43b7a88cf7582627b256f6d1e2177031d9
BLAKE2b-256 checksum
How to use checksums
8d001429cdc663607a7e69a6be12aa5cc41ef1750e976ceb5c480da14e571e93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / dj_cache_tools-0.6.3-py2.py3-none-any.whl

Download URL dj_cache_tools-0.6.3-py2.py3-none-any.whl
Size 8.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
440fc9459eddf63776f63d104d51740da5d45e6f1e602826f723a181c289ee8a
BLAKE2b-256 checksum
How to use checksums
f50a248a75dd58c0455ebd6130624bf21ec04132d5e4c27c6b02e7457829a7f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6.3 This release

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page