Skip to main content

Django context cache library.

Project description

Prolog

Django-context-cache extends the Django framework with a context cache that caches data per request or per decorated block.

Installation

  • Install django-context-cache with the pip command:
pip install django-context-cache
  • Add 'context_cache.middleware.ContextCacheMiddleware' to your MIDDLEWARE:
MIDDLEWARE = [
    'context_cache.middleware.ContextCacheMiddleware',
    ...
]

Usage

Imagine having an function or method which result you want to cache per request:

import random
import string
from context_cache.decorators import cache_for_context

@cache_for_context
def get_random_string():
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for i in range(10))

If you call function get_random_string more times the value will be get from cache:

def view(request):
    get_random_string() == get_random_string() # should return True

If you want to cache an function out of requests, for example in the django command you can use the decorator init_context_cache. The decorator can be used as a context processor too:

from django.core.management.base import BaseCommand, CommandError
from context_cache.decorators import init_context_cache

class Command(BaseCommand):
    
    @init_context_cache
    def handle(self, *args, **options):
        get_random_string() == get_random_string() # should return True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skip-django-context-cache-0.0.2.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file skip-django-context-cache-0.0.2.1.tar.gz.

File metadata

File hashes

Hashes for skip-django-context-cache-0.0.2.1.tar.gz
Algorithm Hash digest
SHA256 7033051e6bbed5a41d63064b8c1af7ec3ce0e88677cec9de8a4b29a698922041
MD5 b5bb988ab034761347cb1f98e29e16a0
BLAKE2b-256 97068e1e88fda41a2f26076fc9484360d76984a3a07f7235b9be8ab62ae15f7b

See more details on using hashes here.

File details

Details for the file skip_django_context_cache-0.0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for skip_django_context_cache-0.0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a0cac4a748eca83ec8093fd9be6c15c1abd9fa5ccb8adeb73d89158b89bcba1
MD5 5b3365d199a6aa09ca3ee493eb54a5b4
BLAKE2b-256 42dec568162b9d4ce8526af1920d27f017492cde91307cbeb05d755e777ec3d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page