djblets.cache.serials¶
Serial numbers used for front-end and back-end caching keys/URLs.
These functions generate stable serial numbers based on the content shipped with the product (static media files, templates, locales). These can be used in various cache keys, ETags, and URLs to help keep content in cache until it changes on disk.
- generate_media_serial()[source]¶
Generate a media serial number for static media files.
The media serial number can be appended to a media filename in order to make a URL that can be cached forever without fear of change. The next time the file is updated and the server is restarted, a new path will be accessed and cached.
This will crawl the media files (using directories in
MEDIA_SERIAL_DIRS
if specified, or all ofSTATIC_ROOT
otherwise), figuring out the latest timestamp, and return that value.
- generate_ajax_serial()[source]¶
Generate a template-based AJAX serial number for requests and ETags.
The serial number can be appended to filenames involving dynamic loads of URLs in order to make a URL that can be cached forever without fear of change.
This will crawl the template files (using directories in
TEMPLATE_DIRS
), figuring out the latest timestamp, and return that value.
- generate_locale_serial(packages)[source]¶
Generate a locale serial for the given set of packages.
This will be equal to the most recent mtime of all the .mo files that contribute to the localization of the given packages.
Unlike the other serial-generation functions, this will return the value, rather than setting it on
settings
.
- generate_cache_serials()[source]¶
Generate both static media and AJAX serial numbers.
This is a wrapper around
generate_media_serial()
andgenerate_ajax_serial()
, which generates all the serial numbers in one go.This should be called early in the startup, such as in the site’s main
urls.py
.