26.5.1 Caching Template Files

Instead of loading templates each time we need one, we can cache any template we load into memory. This means that any subsequent load and render of the template will avoid any disk IO and will instead load the template file from memory. This approach is much, much quicker.

All of the settings for templates can be found in the TEMPLATES setting in suorganizer/settings.py. By default, Django does not list the template loaders used to get and fetch files. Instead, it supplies the key-value 'APP_DIRS': True, which is a shortcut to the app_directories.Loader we are about to add in Example 26.41. If we delete the APP_DIRS key, we can then explicitly set the values for loaders under OPTIONS.

Example 26.41: Project Code ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.