No effort, no worry, maximum performance.
Find a file
Andrew-Chen-Wang d699c5b8c3 Squashed commit of the following:
commit 4a33e7b68196bf6e0ee0b7f942a992532495b616
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Mon Aug 10 16:04:26 2020 -0400

    Replace f-strings with join for Python 3.5

commit dcb33232d605c01025469e776c4ed8eb6ae0a326
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Mon Aug 10 15:55:09 2020 -0400

    Fix sql_flush for dj versions below 3.1
    * Removed any other instances of JSONField for Django 3.1 removed many things like JsonAdapter in favor of regular json module

commit 74195e9ff5a52dba2449a55e543a27ebd99e4fc9
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Mon Aug 10 09:17:03 2020 -0400

    Add Django 3.1 to Travis
    * Specify Django version when checking if JSONField exists

commit da5c1fa4c8b2f2efba0b12d7b27460c544e2473a
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Wed Aug 5 17:39:58 2020 -0400

    Added support for Django 3.1
    * Some fields were removed, others were deprecated. They are now in a list of deprecation to follow. Some new fields were added like PositiveBigIntegerField that won't be tested
    * monkey_patch.py has a try/except import for EmptyResultSet that was from archaic Django. Removed apparently due to compatibility issues
2020-08-10 16:49:46 -04:00
.github Use GitHub's version of python package publish 2020-06-25 15:47:59 -04:00
benchmark/docs/2018-08-09 Updated Docs 2020-02-13 21:15:38 -05:00
cachalot Squashed commit of the following: 2020-08-10 16:49:46 -04:00
docs Added changes to CHANGELOG.rst 2020-07-29 16:10:14 -04:00
requirements Moved tests requirements file 2020-07-09 16:58:35 -04:00
.coveralls.yml Adds the coveralls token. 2014-09-29 22:05:45 +02:00
.gitignore Drop Python 2.7 and Dj 1.11 2020-06-18 09:28:00 -04:00
.travis.yml Squashed commit of the following: 2020-08-10 16:49:46 -04:00
benchmark.py Support benchmarks for MacOS 2020-07-09 18:33:05 -04:00
CHANGELOG.rst Added changes to CHANGELOG.rst 2020-07-29 16:10:14 -04:00
CONTRIBUTING.rst Updated Docs 2020-02-12 01:09:42 -05:00
django-cachalot.jpg Version 0.1.0. 2014-09-26 16:53:44 +02:00
LICENSE Updates to 2016. 2016-01-13 20:02:56 +01:00
MANIFEST.in Version 1.5.0. 2017-06-04 22:00:40 +02:00
README.rst Support benchmarks for MacOS 2020-07-09 18:33:05 -04:00
requirements.txt Drop Python 2.7 and Dj 1.11 2020-06-18 09:28:00 -04:00
runtests.py Version 2.2.0 (#146) 2020-02-12 00:52:12 -05:00
runtests_urls.py Creates a test for CachalotPanel. 2016-10-23 20:06:58 +02:00
settings.py Moves the repository to @NoriPyt. 2018-05-05 02:30:50 +02:00
setup.py Drop Python 2.7 and Dj 1.11 2020-06-18 09:28:00 -04:00
tox.ini Squashed commit of the following: 2020-08-10 16:49:46 -04:00
travis-matrix.py Updates tests for Django 1.11. 2017-06-03 01:53:56 +02:00

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Django Cachalot
===============

Caches your Django ORM queries and automatically invalidates them.

Documentation: http://django-cachalot.readthedocs.io

----

.. image:: http://img.shields.io/pypi/v/django-cachalot.svg?style=flat-square&maxAge=3600
   :target: https://pypi.python.org/pypi/django-cachalot

.. image:: https://travis-ci.com/noripyt/django-cachalot.svg?branch=master
   :target: https://travis-ci.com/noripyt/django-cachalot

.. image:: http://img.shields.io/coveralls/noripyt/django-cachalot/master.svg?style=flat-square&maxAge=3600
   :target: https://coveralls.io/r/noripyt/django-cachalot?branch=master

.. image:: http://img.shields.io/scrutinizer/g/noripyt/django-cachalot/master.svg?style=flat-square&maxAge=3600
   :target: https://scrutinizer-ci.com/g/noripyt/django-cachalot/

.. image:: https://img.shields.io/badge/cachalot-Chat%20on%20Slack-green?style=flat&logo=slack
    :target: https://join.slack.com/t/cachalotdjango/shared_invite/zt-dd0tj27b-cIH6VlaSOjAWnTG~II5~qw

----

Table of Contents:

- Quickstart
- Usage
- Hacking
- Benchmark
- Third-Party Cache Comparison
- Discussion

Quickstart
----------

Cachalot officially supports Python 3.5-3.8 and Django 2.0-2.2, 3.0 with the databases PostgreSQL, SQLite, and MySQL.

Usage
-----

#. ``pip install django-cachalot``
#. Add ``'cachalot',`` to your ``INSTALLED_APPS``
#. If you use multiple servers with a common cache server,
   `double check their clock synchronisation <https://django-cachalot.readthedocs.io/en/latest/limits.html#multiple-servers>`_
#. If you modify data outside Django
    typically after restoring a SQL database ,
   use the `manage.py command <https://django-cachalot.readthedocs.io/en/latest/quickstart.html#command>`_
#. Be aware of `the few other limits <https://django-cachalot.readthedocs.io/en/latest/limits.html#limits>`_
#. If you use
   `django-debug-toolbar <https://github.com/jazzband/django-debug-toolbar>`_,
   you can add ``'cachalot.panels.CachalotPanel',``
   to your ``DEBUG_TOOLBAR_PANELS``
#. Enjoy!

Hacking
-------

To start developing, install the requirements
and run the tests via tox.

Make sure you have the following services:

* Memcached
* Redis
* PostgreSQL
* MySQL

For setup:

#. Install: ``pip install -r requirements/hacking.txt``
#. For PostgreSQL: ``CREATE ROLE cachalot LOGIN SUPERUSER;``
#. Run: ``tox --current-env`` to run the test suite on your current Python version.

Benchmark
---------

Currently, benchmarks are supported on Linux and Mac/Darwin.
You will need a database called "cachalot" on MySQL and PostgreSQL.
Additionally, on PostgreSQL, you will need to create a role
called "cachalot." You can also run the benchmark, and it'll raise
errors with specific instructions for how to fix it.

#. Install: ``pip install -r requirements/benchmark.txt``
#. Run: ``python benchmark.py``

The output will be in benchmark/TODAY'S_DATE/

TODO Create Docker-compose file to allow for easier running of data.

Third-Party Cache Comparison
----------------------------

There are three main third party caches: cachalot, cache-machine, and cache-ops. Which do you use? We suggest a mix:

TL;DR Use cachalot for cold or modified <50 times per seconds (Most people should stick with only cachalot since you
most likely won't need to scale to the point of needing cache-machine added to the bowl). If you're an enterprise that
already has huge statistics, then mixing cold caches for cachalot and your hot caches with cache-machine is the best
mix.

Recall, cachalot caches THE ENTIRE TABLE. That's where its inefficiency stems from: if you keep updating the records,
then the cachalot constantly invalidates the table and re-caches. Luckily caching is very efficient, it's just the cache
invalidation part that kills all our systems. Look at Note 1 below to see how Reddit deals with it.

Cachalot is more-or-less intended for cold caches or "just-right" conditions. If you find a partition library for
Django (also authored but work-in-progress by `Andrew Chen Wang`_), then the caching will work better since sharding
the cold/accessed-the-least records aren't invalidated as much.

Cachalot is good when there are <50 modifications per second on a hot cached table. This is mostly due to cache invalidation. It's the same with any cache,
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
invalidates those individual objects instead of the entire table like cachalot.

Yes, the bane of our entire existence lies in cache invalidation and naming variables. Why does cachalot suck when
stuck with a huge table that's modified rapidly? Since you've mixed your cold (90% of) with your hot (10% of) records,
you're caching and invalidating an entire table. It's like trying to boil 1 ton of noodles inside ONE pot instead of
100 pots boiling 1 ton of noodles. Which is more efficient? The splitting up of them.

Note 1: My personal experience with caches stems from Reddit's: https://redditblog.com/2017/01/17/caching-at-reddit/

Note 2: Technical comparison: https://django-cachalot.readthedocs.io/en/latest/introduction.html#comparison-with-similar-tools

Discussion
----------

Help? Technical chat? `It's here on Slack <https://join.slack.com/t/cachalotdjango/shared_invite/zt-dd0tj27b-cIH6VlaSOjAWnTG~II5~qw>`_.

Legacy chat: https://gitter.im/django-cachalot/Lobby

.. _Andrew Chen Wang: https://github.com/Andrew-Chen-Wang

.. image:: https://raw.github.com/noripyt/django-cachalot/master/django-cachalot.jpg