Caching in Divio Cloud applications¶
See also
Caching in Divio Cloud applications will typically make use of Django’s own caching framework.
Caching options¶
Database caching¶
Our default cache backend is Django’s database caching; all DivioCloud projects are set up with this configured and ready to use.
This is a fast, scalable option, and is suited to most needs.
Database caching is shared by all instances of an application server.
Local per-instance caching¶
Warning
Per-instance caching options are not suitable for django CMS sites,which require synchronisation of data across instances for correctoperation.
Depending on the needs of other applications, you may or may not find thatthese options are suitable.
Per-instance caching options cache data for a particular instance of the cloudapplication server. This means that if your project is running on multipleserver instances, they will not share the caches.
For the same reason if you SSH into a Cloud server and do:
- from django.core.cache import cache
- cache.clear()
in a Python shell, you will only clear the cache in the container you have juststarted up.
Options are:
Third-party caching backends¶
Other backends, such as Redis (a popular open-sourcedatabase) can be used as caching backends for Django.
If it suits your needs, you can procure a Redis or other caching instance froma provider and use it with your Divio Cloud project.
Caching in django CMS¶
The Aldryn django CMS addon applies caching rules by default, via theCMS_CACHE_DURATIONS
setting.
Control over caching settings is exposed in the Divio Cloud Control Panel in the configurationoptions for Aldryn django CMS.
Defaults are to cache content for 60 seconds and menus for one hour.
It is often convenient to disable this while developing or working intensively on content. Adding:
- import os
- env = os.getenv
- STAGE = env('STAGE', 'local').lower()
- if STAGE in {'local', 'test'}:
- CMS_PAGE_CACHE = False
- CMS_PLACEHOLDER_CACHE = False
- CMS_CACHE_DURATIONS = {
- 'menus': 0,
- 'content': 0,
- 'permissions': 0,
- }
to the project’s settings.py
will disable all caching in the CMS in the local and Testenvironments.