Skip to content

Commit 9ad2992

Browse files
committed
Update docs.
1 parent ccd20f2 commit 9ad2992

File tree

5 files changed

+46
-60
lines changed

5 files changed

+46
-60
lines changed

README.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
=========
22
Cacheback
33
=========
4+
45
----------------------------------------
56
Asynchronous cache refreshing for Django
67
----------------------------------------
78

89
What does this library do?
910
--------------------------
11+
1012
It's an extensible caching library that refreshes stale cache items
1113
asynchronously using a Celery_ or rq_ task (utilizing django-rq). The key
1214
idea being that it's better to serve a stale item (and populate the cache
@@ -22,33 +24,41 @@ cache - which can be a significant performance boost.
2224
A corollary of this technique is that cache hammering can be handled simply and
2325
elegantly, avoiding sudden surges of expensive reads when a cached item becomes stale.
2426

27+
2528
Do you have good docs?
2629
----------------------
30+
2731
Yup - `over on readthedocs.org`_.
2832

2933
.. _`over on readthedocs.org`: http://django-cacheback.readthedocs.org/en/latest/
3034

31-
Do you support Python 3?
32-
------------------------
33-
Python 3.4, 3.5, 3.6, 3.7 and PyPy3 are supported.
3435

35-
Django versions 1.8 to 3.0 are supported.
36+
Supported versions
37+
------------------
38+
39+
Python 3.6+ is supported. Django 2.0+ is supported.
40+
3641

3742
Do you have tests?
3843
------------------
44+
3945
You betcha!
4046

4147
.. image:: https://secure.travis-ci.org/codeinthehole/django-cacheback.png
4248
:target: https://travis-ci.org/#!/codeinthehole/django-cacheback
4349

50+
4451
Can I use this in my project?
4552
-----------------------------
53+
4654
Probably - subject to the `MIT license`_.
4755

4856
.. _`MIT license`: https://github.com/codeinthehole/django-cacheback/blob/master/LICENSE
4957

58+
5059
I want to contribute!
5160
---------------------
61+
5262
Brilliant! Here are the `contributing guidelines`_.
5363

5464
.. _`contributing guidelines`: http://django-cacheback.readthedocs.org/en/latest/contributing.html

docs/advanced.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Advanced usage
22
--------------
33

44
Three thresholds for cache invalidation
5-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66

77
It's possible to employ three threshold times to control cache behaviour:
88

docs/api.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
API
33
===
44

5-
The main class is ``cacheback.base.Job``. The methods that are intended to be called from client code are:
5+
The main class is ``cacheback.base.Job``. The methods that are intended to be
6+
called from client code are:
67

78
.. autoclass:: cacheback.base.Job
89
:members: get, invalidate, delete
910

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

1213
.. autoclass:: cacheback.base.Job
13-
:members: lifetime, refresh_timeout, cache_alias, fetch_on_miss, fetch_on_stale_threshold
14+
:members: lifetime, refresh_timeout, cache_alias, fetch_on_miss, fetch_on_stale_threshold, task_options
1415

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

1718
.. autoclass:: cacheback.base.Job
18-
:members: key, fetch, expiry, should_missing_item_be_fetched_synchronously, should_stale_item_be_fetched_synchronously, empty, key, prepare_args, prepare_kwargs, timeout, process_result
19+
:members: key, fetch, expiry, should_missing_item_be_fetched_synchronously, should_stale_item_be_fetched_synchronously, empty, key, prepare_args, prepare_kwargs, timeout, process_result
1920

2021

2122
Queryset jobs
@@ -30,23 +31,22 @@ subclassing but rather take the model class as a ``__init__`` parameter.
3031
.. autoclass:: cacheback.jobs.QuerySetGetJob
3132
:members:
3233

34+
3335
Example usage:
3436

3537
.. sourcecode:: python
36-
38+
3739
from django.contrib.auth import models
3840
from django.shortcuts import render
3941
from cacheback.jobs import QuerySetGetJob, QuerySetFilterJob
4042

4143
def user_detail(request, username):
4244
user = QuerySetGetJob(models.User).get(username=username)
43-
return render(request, 'user.html',
44-
{'user': user})
45+
return render(request, 'user.html', {'user': user})
4546

4647
def staff(request):
4748
staff = QuerySetFilterJob(models.User).get(is_staff=True)
48-
return render(request, 'staff.html',
49-
{'users': staff})
49+
return render(request, 'staff.html', {'users': staff})
5050

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

docs/contributing.rst

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,34 @@
22
Contributing
33
============
44

5-
Start by cloning the repo, creating a virtualenv and running::
5+
Make sure to have `poetry` installed. Then, start by cloning the repo,
6+
and installing the dependencies:
67

7-
$ make install
8+
$ pip install poetry # if not already installed
9+
$ cd <repository directory>
10+
$ poetry install
811

9-
to install the testing dependencies.
1012

1113
Running tests
1214
=============
1315

1416
Use::
1517

16-
$ py.test
18+
# only runs actual tests
19+
$ make pytests
1720

18-
or generate coverage report::
21+
or::
1922

20-
$ py.test --cov
23+
# runs tests but also linters like black, isort and flake8
24+
$ make tests
2125

22-
or use Tox with::
2326

24-
$ tox
25-
26-
to test all Python/Django combinations.
27-
28-
Sandbox VM
29-
==========
30-
31-
There is a ``VagrantFile`` for setting up a sandbox VM where you can play around
32-
with the functionality. Bring up the Vagrant box::
33-
34-
$ vagrant up
27+
To generate html coverage::
3528

36-
This may take a while but will set up a Ubuntu Precise64 VM with RabbitMQ
37-
installed. You can then SSH into the machine::
29+
$ make coverage-html
3830

39-
$ vagrant ssh
40-
$ cd /vagrant/sandbox
4131

42-
You can now decide to run the Celery implementation::
32+
Finally, you can also use tox to run tests against
33+
all supported Django and Python versions::
4334

44-
$ honcho -f Procfile.celery start
45-
46-
Or you can run the RQ implementation::
47-
48-
$ honcho -f Procfile.rq start
49-
50-
The above commands will start a Django runserver and the selected task worker.
51-
The dummy site will be available at ``http://localhost:8080`` on your host
52-
machine. There are some sample views in ``sandbox/dummyapp/views.py`` that
53-
exercise django-cacheback.
35+
$ tox

docs/index.rst

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.. django-async-cache documentation master file, created by
2-
sphinx-quickstart on Mon Jul 30 21:40:46 2012.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
5-
61
================
72
Django Cacheback
83
================
@@ -17,7 +12,7 @@ synchronously.
1712
.. _rq: http://python-rq.org/
1813

1914
Using this library, you can rework your views so that all reads are from
20-
cache - which can be a significant performance boost.
15+
cache - which can be a significant performance boost.
2116

2217
A corollary of this technique is that cache stampedes can be easily avoided,
2318
avoiding sudden surges of expensive reads when cached items becomes stale.
@@ -37,24 +32,24 @@ Consider a view for showing a user's tweets:
3732
from myproject.twitter import fetch_tweets
3833

3934
def show_tweets(request, username):
40-
return render(request, 'tweets.html',
35+
return render(request, 'tweets.html',
4136
{'tweets': fetch_tweets(username)})
4237

4338
This works fine but the ``fetch_tweets`` function involves a HTTP round-trip and
44-
is slow.
39+
is slow.
4540

4641
Performance can be improved by using Django's `low-level cache API`_:
4742

4843
.. _`low-level cache API`: https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs#the-low-level-cache-api
49-
44+
5045
.. sourcecode:: python
5146

5247
from django.shortcuts import render
5348
from django.cache import cache
5449
from myproject.twitter import fetch_tweets
5550

5651
def show_tweets(request, username):
57-
return render(request, 'tweets.html',
52+
return render(request, 'tweets.html',
5853
{'tweets': fetch_cached_tweets(username)})
5954

6055
def fetch_cached_tweets(username):
@@ -88,7 +83,7 @@ cache asynchronously instead of during the request/response cycle:
8883
from myproject.tasks import update_tweets
8984

9085
def show_tweets(request, username):
91-
return render(request, 'tweets.html',
86+
return render(request, 'tweets.html',
9287
{'tweets': fetch_cached_tweets(username)})
9388

9489
def fetch_cached_tweets(username):
@@ -116,7 +111,7 @@ where the ``myproject.tasks.update_tweets`` task is implemented as:
116111
def update_tweets(username, ttl):
117112
tweets = fetch_tweets(username)
118113
now = datetime.datetime.now()
119-
cache.set(username, (tweets, now+ttl), 2592000)
114+
cache.set(username, (tweets, now+ttl), 2592000)
120115

121116
Some things to note:
122117

@@ -147,7 +142,7 @@ Here's the same functionality implemented using a django-cacheback decorator:
147142
from cacheback.decorators import cacheback
148143

149144
def show_tweets(request, username):
150-
return render(request, 'tweets.html',
145+
return render(request, 'tweets.html',
151146
{'tweets': cacheback(60*15, fetch_on_miss=False)(fetch_tweets)(username)})
152147

153148
Here the decorator simply wraps the ``fetch_tweets`` function - nothing else is
@@ -206,4 +201,3 @@ Indices and tables
206201
* :ref:`genindex`
207202
* :ref:`modindex`
208203
* :ref:`search`
209-

0 commit comments

Comments
 (0)