Now that you've seen the various cache backends that Django offers, we can now start implementing the code to work with them. Regardless of the backend you chose, the code will be identical.
To tell Django which backend we intend to use, we will set a variable called CACHE_BACKEND
in our mycompany/settings.py
file. Each backend uses a slightly different value, so we'll run through each separately.
In order to use the database caching backend, you also have to run the createcachetable
command from the manage.py
file. This example uses my_cache_table
as the name of the table, but you're free to use whatever you like:
$ python manage.py createcachetable my_cache_table
Once you have your cache table set up, add the backend to your mycompany/settings.py
file:
CACHE_BACKEND = 'db://my_cache_table'