Skip to content

ntucker/django-cache-magic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django-Cache-Magic

Cache magic 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 django-cache-magic

Usage

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

from django.db import models
from cachemagic import CacheController

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

    cache = CacheController()

myModel.cache.get(pk=27)

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

Find the complete documentation at django-cache-magic.readthedocs.org.

Thanks

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

About

Helpful bits to make caching and cache invalidation as painless as possible in Django!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%