Giter Site home page Giter Site logo

django-autocache's Introduction

Django-Autocache

Autocache addresses two common scenarios for caching and cache invalidation for django models: instance caching and related objects caching.

Instance caching: Storing instances of objects in your cache layer as well as your database.

Related objects caching: Storing a collection of objects related to another object referenced by relational constraints (ForeignKey, ManyToMany, etc.)

Installing

pip install -e "git+git://github.com/noah256/django-autocache.git#egg=autocache"

Usage

To start autocaching model instances, add a CacheController to your model:

from django.db import models
from autocache import CacheController

class myModel(models.Model):
    f1 = models.IntegerField()
    f2 = models.TextField()

    cache = CacheController()

myModel.cache.get(pk=27)

When using autocache, you should avoid django operations that update multiple rows at once, since these operations typically don't emit the signals that autocache relies on for cache invalidation. This includes methods like Queryset.update, Queryset.delete, and RelatedManager.clear

Find the complete documentation at django-autocache.readthedocs.org.

Running the tests

Django-Autocache has a sample django application that tests the caching machinery. To run tests, start by cloning the autocache repository and entering the test_project directory.

The tests run using memcached and pylibmc. You can change the backend by editing autocache/tests/settings.py. (TODO: get the test suite to run multiple times with different backends)

  • Start two memcached servers (testing multicache)
    • memcached -p 11211 -U 0
    • memcached -p 11212 -U 0
  • Change into the autocache/test_project/ directory and run manage.py test

Thanks

Big thanks to Travis Fischer for drafting a lot of documentation and tests!

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.