| 1 |
*************** |
| 2 |
django-cachalot |
| 3 |
*************** |
| 4 |
|
| 5 |
Caches your Django ORM queries and automatically invalidates them. |
| 6 |
|
| •7 |
.. image:: //usr/share/doc/python-django-cachalot-doc/html/_images/django-cachalot.jpg |
| 8 |
|
| 9 |
---- |
| 10 |
|
| 11 |
Usage |
| 12 |
..... |
| 13 |
|
| 14 |
#. ``pip install django-cachalot`` |
| 15 |
#. Add ``'cachalot',`` to your ``INSTALLED_APPS`` |
| 16 |
#. If you use multiple servers with a common cache server, |
| 17 |
:ref:`double check their clock synchronisation <Multiple servers>` |
| 18 |
#. If you modify data outside Django |
| 19 |
– typically after restoring a SQL database –, |
| 20 |
use the :ref:`manage.py command <Command>` |
| 21 |
#. Be aware of :ref:`the few other limits <Limits>` |
| 22 |
#. If you use |
| 23 |
`django-debug-toolbar <https://github.com/jazzband/django-debug-toolbar>`_, |
| 24 |
you can add ``'cachalot.panels.CachalotPanel',`` |
| 25 |
to your ``DEBUG_TOOLBAR_PANELS`` |
| 26 |
#. Enjoy! |
| 27 |
|
| 28 |
Note: In settings, you can use :ref:`CACHALOT_UNCACHABLE_TABLES` as a frozenset of table names (e.g. "public_test" if public was the app name and test is a model name). |
| 29 |
|
| 30 |
Why use cachalot? :ref:`Check out our comparison <Comparison with similar tools>` |
| 31 |
|
| 32 |
Below the tree is an in-depth opinion from the new maintainer: |
| 33 |
|
| 34 |
.. toctree:: |
| 35 |
:maxdepth: 2 |
| 36 |
|
| 37 |
introduction |
| 38 |
quickstart |
| 39 |
limits |
| 40 |
api |
| 41 |
benchmark |
| 42 |
todo |
| 43 |
reporting |
| 44 |
how |
| 45 |
legacy |
| 46 |
changelog |
| 47 |
|
| 48 |
In-depth opinion (from new maintainer): |
| 49 |
|
| 50 |
There are three main third party caches: cachalot, cache-machine, and cache-ops. Which do you use? We suggest a mix: |
| 51 |
|
| 52 |
TL;DR Use cachalot for cold or modified <50 times per minutes (Most people should stick with only cachalot since you |
| 53 |
most likely won't need to scale to the point of needing cache-machine added to the bowl). If you're an enterprise that |
| 54 |
already has huge statistics, then mixing cold caches for cachalot and your hot caches with cache-machine is the best |
| 55 |
mix. However, when performing joins with select_related and prefetch_related, you can |
| 56 |
get a nearly 100x speed up for your initial deployment. |
| 57 |
|
| 58 |
Recall, cachalot caches THE ENTIRE TABLE. That's where its inefficiency stems from: if you keep updating the records, |
| 59 |
then the cachalot constantly invalidates the table and re-caches. Luckily caching is very efficient, it's just the cache |
| 60 |
invalidation part that kills all our systems. Look at Note 1 below to see how Reddit deals with it. |
| 61 |
|
| 62 |
Cachalot is more-or-less intended for cold caches or "just-right" conditions. If you find a partition library for |
| 63 |
Django (also authored but work-in-progress by `Andrew Chen Wang <https://github.com/Andrew-Chen-Wang>`_), |
| 64 |
then the caching will work better since sharding the cold/accessed-the-least records aren't invalidated as much. |
| 65 |
|
| 66 |
Cachalot is good when there are <50 modifications per minute on a hot cached table. This is mostly due to cache invalidation. It's the same with any cache, |
| 67 |
which is why we suggest you use cache-machine for hot caches. Cache-machine caches individual objects, taking up more in the memory store but |
| 68 |
invalidates those individual objects instead of the entire table like cachalot. |
| 69 |
|
| 70 |
Yes, the bane of our entire existence lies in cache invalidation and naming variables. Why does cachalot suck when stuck |
| 71 |
with a huge table that's modified rapidly? Since you've mixed your cold (90% of) with your hot (10% of) records, you're |
| 72 |
caching and invalidating an entire table. It's like trying to boil 1 ton of noodles inside ONE pot instead of 100 pots |
| 73 |
boiling 1 ton of noodles. Which is more efficient? The splitting up of them. |
| 74 |
|
| 75 |
Note 1: My personal experience with caches stems from Reddit's: https://redditblog.com/2017/01/17/caching-at-reddit/ |