Debian Codegraph @

README.rst

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 Django Cachalot
2 ===============
3
4 Caches your Django ORM queries and automatically invalidates them.
5
6 Documentation: http://django-cachalot.readthedocs.io
7
8 ----
9
10 .. image:: http://img.shields.io/pypi/v/django-cachalot.svg?style=flat-square&maxAge=3600
11 :target: https://pypi.python.org/pypi/django-cachalot
12
13 .. image:: https://img.shields.io/pypi/pyversions/django-cachalot
14 :target: https://django-cachalot.readthedocs.io/en/latest/
15
16 .. image:: https://github.com/noripyt/django-cachalot/actions/workflows/ci.yml/badge.svg
17 :target: https://github.com/noripyt/django-cachalot/actions/workflows/ci.yml
18
19 .. image:: http://img.shields.io/coveralls/noripyt/django-cachalot/master.svg?style=flat-square&maxAge=3600
20 :target: https://coveralls.io/r/noripyt/django-cachalot?branch=master
21
22 .. image:: http://img.shields.io/scrutinizer/g/noripyt/django-cachalot/master.svg?style=flat-square&maxAge=3600
23 :target: https://scrutinizer-ci.com/g/noripyt/django-cachalot/
24
25 .. image:: https://img.shields.io/discord/773656139207802881
26 :target: https://discord.gg/WFGFBk8rSU
27
28 ----
29
30 Table of Contents:
31
32 - Quickstart
33 - Usage
34 - Hacking
35 - Benchmark
36 - Third-Party Cache Comparison
37 - Discussion
38
39 Quickstart
40 ----------
41
42 Cachalot officially supports Python 3.8-3.14 and Django 4.2, 5.2, 6.0, 6.1 with the databases PostgreSQL, SQLite, and MySQL.
43
44 Note: an upper limit on Django version is set for your safety. Please do not ignore it.
45
46 Usage
47 -----
48
49 #. ``pip install django-cachalot``
50 #. Add ``'cachalot',`` to your ``INSTALLED_APPS``
51 #. If you use multiple servers with a common cache server,
52 `double check their clock synchronisation <https://django-cachalot.readthedocs.io/en/latest/limits.html#multiple-servers>`_
53 #. If you modify data outside Django
54 – typically after restoring a SQL database –,
55 use the `manage.py command <https://django-cachalot.readthedocs.io/en/latest/quickstart.html#command>`_
56 #. Be aware of `the few other limits <https://django-cachalot.readthedocs.io/en/latest/limits.html#limits>`_
57 #. If you use
58 `django-debug-toolbar <https://github.com/jazzband/django-debug-toolbar>`_,
59 you can add ``'cachalot.panels.CachalotPanel',``
60 to your ``DEBUG_TOOLBAR_PANELS``
61 #. Enjoy!
62
63 Hacking
64 -------
65
66 To start developing, install the requirements
67 and run the tests via tox.
68
69 Make sure you have the following services:
70
71 * Memcached
72 * Redis
73 * PostgreSQL
74 * MySQL
75
76 For setup:
77
78 #. Install: ``pip install -r requirements/hacking.txt``
79 #. For PostgreSQL: ``CREATE ROLE cachalot LOGIN SUPERUSER;``
80 #. Run: ``tox --current-env`` to run the test suite on your current Python version.
81 #. You can also run specific databases and Django versions: ``tox -e py312-django5.2-postgresql-redis``
82
83 Benchmark
84 ---------
85
86 Currently, benchmarks are supported on Linux and Mac/Darwin.
87 You will need a database called "cachalot" on MySQL and PostgreSQL.
88 Additionally, on PostgreSQL, you will need to create a role
89 called "cachalot." You can also run the benchmark, and it'll raise
90 errors with specific instructions for how to fix it.
91
92 #. Install: ``pip install -r requirements/benchmark.txt``
93 #. Run: ``python benchmark.py``
94
95 The output will be in benchmark/TODAY'S_DATE/
96
97 TODO Create Docker-compose file to allow for easier running of data.
98
99 Third-Party Cache Comparison
100 ----------------------------
101
102 There are three main third party caches: cachalot, cache-machine, and cache-ops. Which do you use? We suggest a mix:
103
104 TL;DR Use cachalot for cold or modified <50 times per minutes (Most people should stick with only cachalot since you
105 most likely won't need to scale to the point of needing cache-machine added to the bowl). If you're an enterprise that
106 already has huge statistics, then mixing cold caches for cachalot and your hot caches with cache-machine is the best
107 mix. However, when performing joins with ``select_related`` and ``prefetch_related``, you can
108 get a nearly 100x speed up for your initial deployment.
109
110 Recall, cachalot caches THE ENTIRE TABLE. That's where its inefficiency stems from: if you keep updating the records,
111 then the cachalot constantly invalidates the table and re-caches. Luckily caching is very efficient, it's just the cache
112 invalidation part that kills all our systems. Look at Note 1 below to see how Reddit deals with it.
113
114 Cachalot is more-or-less intended for cold caches or "just-right" conditions. If you find a partition library for
115 Django (also authored but work-in-progress by `Andrew Chen Wang`_), then the caching will work better since sharding
116 the cold/accessed-the-least records aren't invalidated as much.
117
118 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,
119 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
120 invalidates those individual objects instead of the entire table like cachalot.
121
122 Yes, the bane of our entire existence lies in cache invalidation and naming variables. Why does cachalot suck when
123 stuck with a huge table that's modified rapidly? Since you've mixed your cold (90% of) with your hot (10% of) records,
124 you're caching and invalidating an entire table. It's like trying to boil 1 ton of noodles inside ONE pot instead of
125 100 pots boiling 1 ton of noodles. Which is more efficient? The splitting up of them.
126
127 Note 1: My personal experience with caches stems from Reddit's: https://web.archive.org/web/20210803213621/https://redditblog.com/2017/01/17/caching-at-reddit/
128
129 Note 2: Technical comparison: https://django-cachalot.readthedocs.io/en/latest/introduction.html#comparison-with-similar-tools
130
131 Discussion
132 ----------
133
134 Help? Technical chat? `It's here on Discord <https://discord.gg/WFGFBk8rSU>`_.
135
136 Legacy chats:
137
138 - https://gitter.im/django-cachalot/Lobby
139 - https://join.slack.com/t/cachalotdjango/shared_invite/zt-dd0tj27b-cIH6VlaSOjAWnTG~II5~qw
140
141 .. _Andrew Chen Wang: https://github.com/Andrew-Chen-Wang
142
143 .. image:: https://raw.github.com/noripyt/django-cachalot/master/django-cachalot.jpg