Git Product home page Git Product logo

django-cache's Introduction

Django-cache

Enhanced cache_page decorator for Django views.

image

image

Compatibility

Django-cache properly works with Django 1.8, 1.9, 1.10 and 1.11 on Python 2.7, 3.4, 3.5 and 3.6.

Advantages

  • fixed certain amount of bugs (including #15855)
  • support of callable cache_timeout and key_prefix parameters
  • cache age can be limited by client (min cache age is manageable, default is 0)

Usage

from djangocache import cache_page

@cache_page(cache_timeout=600)
def view(request):
    pass

Combination with last_modified and/or etag view decorators

If you planning to use cache_page among with last_modified and/or etag the latter must be placed after cache_page:

from djangocache import cache_page
from django.views.decorators.http import last_modified, etag

def etag_generator(request, *args, **kwargs):
    return 'ETag!!'

@cache_page(cache_timeout=600)
@etag(etag_generator)
def view(request, *args, **kwargs):
    pass

Django Settings

DJANGOCACHE_MIN_AGE - used to set minimal age of cache. Default is 0, meaning that client can ask server to skip cache by providing header Cache-Control: max-age=0.

@cache_page params

  • cache_timeout. Default is settings.CACHE_MIDDLEWARE_SECONDS.
  • key_prefix. Default is settings.CACHE_MIDDLEWARE_KEY_PREFIX.
  • cache_alias. Default is settings.CACHE_MIDDLEWARE_ALIAS, or settings.DEFAULT_CACHE_ALIAS if set to None.
  • cache_min_age. Default is settings.DJANGOCACHE_MIN_AGE.

Installation

pip install --upgrade django-cache

django-cache's People

Contributors

renskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.