Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.63 KB

api.rst

File metadata and controls

50 lines (34 loc) · 1.63 KB

API

The main class is cacheback.base.Job. The methods that are intended to be called from client code are:

cacheback.base.Job

It has some class properties than can be used to configure simple behaviour:

cacheback.base.Job

There are also several methods intended to be overridden and customised:

cacheback.base.Job

Queryset jobs

There are two classes for easy caching of ORM reads. These don't need subclassing but rather take the model class as a __init__ parameter.

cacheback.queryset.QuerySetFilterJob

cacheback.queryset.QuerySetGetJob

Example usage:

from django.contrib.auth import models
from django.shortcuts import render
from cacheback.queryset import QuerySetGetJob, QuerySetFilterJob

def user_detail(request, username):
    user = QuerySetGetJob(models.User).get(username=username)
    return render(request, 'user.html',
                  {'user': user})

def staff(request):
    staff = QuerySetFilterJob(models.User).filter(is_staff=True)
    return render(request, 'staff.html',
                  {'users': staff})

These classes are helpful for simple ORM reads but won't be suitable for more complicated queries where filter is chained together with exclude.